我正在使用 Windows 和 C 语言中的默认 LISTBOX 类创建一个 LISTBOX。
列表框被正确地绘制到主窗口上,但是当我尝试随后用任何数据填充它时,它会默默地失败。SendMessage()
每次返回 0。列表框的句柄已被确认是正确的,LB_ADDSTRING
定义是0x0180
(我认为这也是正确的)。
我已经尝试过char *
文字wchar_t *
字符串,它们都不会出现,SendMessage()
无论调用多少次,它们都从调用中返回 0。我只能假设我的消息处理程序或我的类和窗口创建可能不正确。以下是相关代码的最新版本:
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;
}