Check Box Question
In which part of my code do I test whether a check box has been clicked ?
Here's some of my code:
Thanks heaps :D
// my own two functions:
bool CheckBox(HWND hDlg, HWND button)
if( SendMessage(hDlg, BM_GETCHECK, 0, 0) == BST_CHECKED )
void MakeActive(HWND hDlg, HWND winone, HWND wintwo)
// the code to test the check box:
if(CheckBox(hDlg, mon_check) == TRUE)
MakeActive(hDlg, mon_one, mon_two);
The help is unclear on this msg. I use IsDlgButtonChecked() macro instead from winuser.h.
if(BST_CHECKED == IsDlgButtonChecked(hDialog , IDC_BUTTON) )
AFAIK you need to send the HWND of the button not of the dlg if using SendMessage(). (Else how does it know which button you want to check?)
When do you send the message?
When you need to know if the button is checked. Probably when the user activates another control.
I want to see if its checked right after they check it
In the dialogs callback, under the WM_COMMAND case 's switch you will have a case for the button. Use the code there.
idControl = GET_WM_COMMAND_ID(wParam,lParam) ;
if (BN_CLICKED == HIWORD(wParam))
//button has been clicked so now find its check state
Here it goes. The IDC_CHKBOX is a #define and is the button ID.
bool CheckBox (HWND hWnd)
if (IsDlgButtonChecked (hWnd, IDC_CHKBOX))
>>if (IsDlgButtonChecked (hWnd, IDC_CHKBOX))
This will not work correctly as there is three returns from the macro
0 = unchecked
1 = checked
2 = undetermined (also a true)
not to mention if the #defined returns numeriacl value should be changed.