Reputation: 21389
I've been afraid to ask as I'm sure the answer is very simple, but I've been bashing my head against the wall for several days on this one simple thing now and am making no forward progress.
I have a basic window with a checkbox inside of it like this (ignoring all the standard WndProc boilerplate), and am allowing dialog processing (as in my full application I have input fields that I allow tabbing through):
hwnd := CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "Sample", WS_VISIBLE + WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 350, 420, NIL, menu, MyInstance(), NIL);
gfhwnd := CreateWindowEx(WS_EX_CLIENTEDGE, "Button", "", WS_CHILD + BS_CHECKBOX + WS_TABSTOP, 250, 130, 17, 17, hwnd, NIL, MyInstance(), NIL);
ShowWindow(hwnd, SW_SHOWNORMAL);
ShowWindow(gfhwnd, SW_SHOWNORMAL);
WHILE GetMessage( Msg, NIL, 0, 0) DO
IF NOT IsDialogMessage(hwnd, Msg) THEN
TranslateMessage(Msg);
DispatchMessage(Msg);
END; (* IF *)
END; (* WHILE *)
My understanding is that the checkbox should straight out of the gate be enabled and can be checked on/off via click or keyboard. However, it won't. It's always off. If clicked (or keyboard activated), the button flashes briefly then returns to unchecked. If I capture the messages in WM_COMMAND it is always telling me that I clicked to "CHECK" the box. I never get an "UNCHECK" event. So, at least it is internally consistent. Since I'm getting messages it does appear to be enabled.
So far I've tried many variations on capturing the clicks and then forcing the checkbox in/out of the checked state (including assigning it custom IDs as well as not). However, out of all the various methods I've found via Google, none of them work. In all cases the checkbox stays quite firmly "unchecked". What tiny, but critical, piece of knowledge am I missing about how checkboxes work in Windows?
Upvotes: 0
Views: 25