-
Missing checkbox...
I have 3 buttons on my window and 1 checkbox. I get no errors
when my program compiles/links but when it runs the checkbox is
no where to be found.
Here's my code:
Code:
//in my message handler
case WM_CREATE:
CreateWindowEx(0,"Button","End Turn",WS_CHILD | WS_VISIBLE
| BS_DEFPUSHBUTTON,245,50,60,30,hwnd,
NULL,hInstMain,NULL);
CreateWindowEx(0,"CheckBox","CheckBox",WS_CHILD |
WS_VISIBLE | BS_CHECKBOX,245,90,60,30,hwnd,
NULL,hInstMain,NULL);
Any ideas of what I'm doing wrong? The MSDN library wasn't too helpful. Thanks in advance for any advice.
-
You are passing the wrong class name to the CreateWindowEx function it should be "button" not "checkbox", b/c a checkbox is a type of button. Just change that and it should work fine.
-
Thanks, xds4lx. That fixed that problem, but now I've got a new one. How do I change the state of the checkbox. I can identify when it was clicked on (by checking the (HWND)lparam value when a WM_COMMAND message comes in) but I don't know how to "check/uncheck" the checkbox.
I read through the MSDN help for it and tried the CButton::Create(blah,blah,blah) but it gave me errors like:
error C2653: 'CButton' : is not a class or namespace name
error C2065: 'Create' : undeclared identifier
I've tried declaring an instance of the CButton class with:
CButton cbCheckBox;
And then using:
cbCheckBox("Test",WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
&rcCheckBox,&hwnd,NULL);
This gives me errors:
error C2146: syntax error : missing ';' before identifier 'cbCB'
error C2501: 'CButton' : missing storage-class or type specifiers
error C1004: unexpected end of file found
Does anyone know of a good tutorial for using Command Buttons/Checkboxes, etc. WITHOUT using MFC?
Again, thanks.
-
Ok, when you are processing the WM_COMMAND message you should do something like this:
Code:
....
case WM_COMMAND:
{ switch(LOWORD(wParam)) // which control (button or otherwise
{ // caused the message
case MY_CHECKBOX: // this should be the id you used when
{ // creating your "button"
switch(HIWORD(wParam))
{ case BN_CLICKED:
{ SendMessage(hButton, BM_SETCHECK, 1,0);
// The params are the control (or buttons hwnd,
// the message to send, this case button set
//check, 1 to tell it to check, 0 to uncheck, and
//the last param should always be a 0!, or you
//can use BM_GETCHECK to check the state of the
//button, just look up "Button Messages in msdn"
return(0);
}
default:
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
return(0);
}
}
-
Thanks again, xds4lx! It actually makes sense now. :D