This code works:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"
#define NELEMS(a) (sizeof(a) / sizeof((a)[0]))
static HANDLE ghInstance;
void hwndDlg_OnClose(HWND hwnd)
{
ExitProcess(0);
}
void hwndDlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
if(id==IDOK) {
HWND textedit = GetDlgItem(hwnd,4001);
HWND listbox = GetDlgItem(hwnd,4002);
char buf[25];
GetDlgItemText(hwnd,4001,buf,20);
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)buf);
}
}
BOOL CALLBACK MainDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
HANDLE_MSG (hwndDlg, WM_CLOSE, hwndDlg_OnClose);
HANDLE_MSG (hwndDlg, WM_COMMAND, hwndDlg_OnCommand);
default: return FALSE;
}
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
ghInstance = hInstance;
/* Get system dialog information */
wcx.cbSize = sizeof(wcx);
if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;
/* Add our own stuff */
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("testClass");
if (!RegisterClassEx(&wcx))
return 0;
/* The user interface is a modal dialog box */
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}
I guess I must have that class registration there. Very strange...