BS_AUTOCHECKBOX always returning UNCHECKED state

I have a checxkbox created with CreateWindowEx

1
2
3
4
HWND checkbox = CreateWindowEx(0, 
"BUTTON", "Click here to activate", 
BS_AUTOCHECKBOX|WS_VISIBLE|WS_CHILD, 
85, 250, 200, 20, hWnd, (HMENU)CCK_ACTIVATE, hInstance, NULL );


and I want to get its state with a SendMessage like this when I click on the control

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
        case WM_COMMAND:
            if(((HWND)lParam) && (HIWORD(wParam) == BN_CLICKED)) {
                switch(LOWORD(wParam)) {
                    case CCK_ACTIVATE:
                        if (SendMessage(checkbox, BM_GETCHECK, 0, 0) == BST_UNCHECKED) {
                            MessageBox(NULL, "Activated", NULL, NULL);
                        } else {
                             MessageBox(NULL, "Deactivated", NULL, NULL);
                        }
                    break;
                }
            }
        break;
...


What happens is that I always get the BST_UNCHECKED state, even when the checkbox is checked. This is so creepy (something that is supposed to just work and it doesn't for unexplicable reasons).
Thanks for your answers in advance!
Last edited on
Set the WPARAM to TRUE --

if(SendMessage(checkbox,BM_GETCHECK,TRUE,0)==BST_UNCHECKED)
Well, I did it (even if MSDN says that it must be set to 0) but the same happens again. It's like the checkbox is unable to set it status to BST_CHECKED when I click on it. I inserted this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
        case WM_COMMAND:
            if(((HWND)lParam) && (HIWORD(wParam) == BN_CLICKED)) {
                switch(LOWORD(wParam)) {
                    case CCK_ACTIVATE:
                        if (SendMessage(checkbox, BM_GETCHECK, 0, 0) == BST_UNCHECKED) {
                            MessageBox(NULL, "Activated", NULL, NULL);
                            SendMessage(checkbox, BM_SETCHECK, WPARAM(BST_CHECKED), 0);
                        } else {
                             MessageBox(NULL, "Deactivated", NULL, NULL);
                        }
                    break;
                }
            }
        break;
...


Even so, it still doesn't change its status to BST_CHECKED. Keep trying...
Last edited on
The only thing I could suggest at the moment is to try to change it from BS_AUTOCHECKBOX to BS_CHECKBOX and see if that has any effect.

I'm also not sure your (HWND)lParam just under you WM_COMMAND is correct, but I'll have to look into that later when I have time.
Last edited on
You can also try this --

if(LOWORD(wParam)==CCK_ACTIVATE && HIWORD(wParam)==BN_CLICKED)

Of course, you must remove your other if() statement as well as the switch operator.
Last edited on
Topic archived. No new replies allowed.