What is the source code to do the standard checkbox actions with a Visual C++ MFC checkbox control?
Controlling Checkboxes in MFC
Here's how to check, uncheck, enable, and disable a checkbox in MFC:
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->SetCheck(0);// uncheck it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->SetCheck(1);// check it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->EnableWindow(0);// disable it
CButton* pBtn = (CButton*) GetDlgItem(IDC_SETUP_AM);
pBtn->EnableWindow(1);// enable it
bool isRemoveChecked = IsDlgButtonChecked(IDC_removeProf);
Alternatively, you won't need to retrieve a pointer to the button (checkbox) if you use CWnd::CheckDlgButton to check/un-check the button, for example:
BOOL isChecked = ...
CheckDlgButton(IDC_SOME_ID, isChecked);
And, enabling/disabling can be simplified to:
BOOL isEnabled = ...
GetDlgItem(IDC_SOME_ID)->EnableWindow(isEnabled);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With