I am creating a LISTBOX using the default LISTBOX class in Windows and the C language.
The Listbox is drawn onto the main window properly, but when I try to subsequently fill it with any data, it silently fails. SendMessage()
returns 0 every time. The handle to the listbox has been confirmed to be proper, the LB_ADDSTRING
definition is 0x0180
(which I assume is also proper).
I have tried char *
and wchar_t *
and literal strings, none of them will show up, all of them return 0 from SendMessage()
calls no matter how many times it is called. I am left to assume that perhaps my message handler, or my class and window creation, are incorrect. Here is the most recent version of the associated code:
LRESULT CALLBACK DBWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch ( uMsg )
{
case WM_CREATE:
break;
case WM_PAINT:
break;
case WM_DESTROY:
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
void DBClassBuilder()
{
WNDCLASSEX wc;
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = DBWinProc;
wc.hInstance = g_pi.hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = TEXT("LISTBOX");
if ( !RegisterClassEx(&wc) )
return;
g_pi.hb.hDBListBox = CreateWindowEx(
0, TEXT("LISTBOX"),
TEXT(""),
WS_CHILD | LBS_HASSTRINGS | LBS_STANDARD,
0, 0, 100, 300,
g_pi.hWnd, NULL, g_pi.hInstance, NULL);
if ( g_pi.hb.hDBListBox == NULL )
return;
SendMessage(g_pi.hb.hDBListBox, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(FALSE,0));
ShowWindow(g_pi.hb.hDBListBox, g_pi.nCmdShow);
UpdateWindow(g_pi.hb.hDBListBox);
}
LRESULT CALLBACK MainWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
g_pi.hWnd = hWnd;
switch ( uMsg )
{
case WM_CREATE:
SaveMainPos();
DBClassBuilder();
SendMessage(g_pi.hb.hDBListBox, LB_ADDSTRING, 0, (LPARAM)"test");
break;
case WM_PAINT:
SaveMainPos();
UpdateChildren();
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}