Reputation: 4455
As the title states my problem is with the expanded list of a WinAPI combo box showing up blank when opened. Any subsequent updates (as when moving the cursor around) will redraw the affected items however. In addition the list won't respond to any mouse input. This happens in both Windows XP as well as 7.
As near as I can tell in Spy++ the modal list receives WM_ERASEBKGND but stops short of processing WM_PAINT. Showing a combo box in a modal dialog box works nicely, by the way, but creating the control as part of a regular top-level window or spawning the same dialog template as a modeless child window does not.
I'm guessing I've forgotten something rather basic and embarrassing, e.g. not setting a clipping style or calling DoDialogMagic in the message loop or some such, but I just can't seem to figure it out on my own.
Anyway, here's a minimal repro case:
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "comctl32.lib")
INT CALLBACK _tWinMain(HINSTANCE instance, HINSTANCE parent, LPTSTR commands, INT show) {
static const TCHAR title[] = _T("Combo Problem");
HWND hwnd;
HWND combo;
MSG msg;
/* First create our parent window */
const WNDCLASS cls = {
/* style */ 0,
/* lpfnWndProc */ DefWindowProc,
/* cbClsExtra */ 0,
/* cbWndExtra */ 0,
/* hInstance */ instance,
/* hIcon */ NULL,
/* hCursor */ LoadCursor(NULL, IDC_ARROW),
/* hbrBackground */ (HBRUSH) (COLOR_INACTIVEBORDER + 1),
/* lpszMenuName */ NULL,
/* lpszClassName */ title
};
RegisterClass(&cls);
hwnd = CreateWindow (
/* lpClassName */ title,
/* lpWindowName */ title,
/* dwStyle */ WS_OVERLAPPEDWINDOW | WS_VISIBLE,
/* x */ CW_USEDEFAULT,
/* y */ CW_USEDEFAULT,
/* nWidth */ 125,
/* nHeight */ 70,
/* hWndParent */ NULL,
/* hMenu */ NULL,
/* hInstance */ instance,
/* lpParam */ NULL
);
/* Now create and populate the combo box itself */
InitCommonControls();
combo = CreateWindow (
/* lpClassName */ _T("COMBOBOX"),
/* lpWindowName */ _T(""),
/* dwStyle */ CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE,
/* x */ 10,
/* y */ 10,
/* nWidth */ 100,
/* nHeight */ 150,
/* hWndParent */ hwnd,
/* hMenu */ NULL,
/* hInstance */ instance,
/* lpParam */ NULL
);
SendMessage(combo, CB_ADDSTRING, 0, (LPARAM) _T("Alpha"));
SendMessage(combo, CB_ADDSTRING, 0, (LPARAM) _T("Beta"));
SendMessage(combo, CB_ADDSTRING, 0, (LPARAM) _T("Gamma"));
/* Finally run the message pump */
while(GetMessage(&msg, hwnd, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Upvotes: 1
Views: 839
Reputation: 101756
You are passing a hwnd to GetMessage, this is usually not what you want, just use NULL.
Upvotes: 1