-
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:
Code:
// my own two functions:
bool CheckBox(HWND hDlg, HWND button)
{
if( SendMessage(hDlg, BM_GETCHECK, 0, 0) == BST_CHECKED )
{
return TRUE;
}
else
{
return FALSE;
}
}
void MakeActive(HWND hDlg, HWND winone, HWND wintwo)
{
EnableWindow(winone, TRUE);
EnableWindow(wintwo, TRUE);
}
// the code to test the check box:
if(CheckBox(hDlg, mon_check) == TRUE)
{
MakeActive(hDlg, mon_one, mon_two);
}
Thanks heaps :D
-
The help is unclear on this msg. I use IsDlgButtonChecked() macro instead from winuser.h.
ie
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
-
OK
In the dialogs callback, under the WM_COMMAND case 's switch you will have a case for the button. Use the code there.
Code:
case WM_COMMAND:
idControl = GET_WM_COMMAND_ID(wParam,lParam) ;
switch(idControl)
{
case IDC_BUTTON:
if (BN_CLICKED == HIWORD(wParam))
//button has been clicked so now find its check state
-
Like this
Here it goes. The IDC_CHKBOX is a #define and is the button ID.
bool CheckBox (HWND hWnd)
{
if (IsDlgButtonChecked (hWnd, IDC_CHKBOX))
return TRUE;
return FALSE;
}
-
>>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.