How to check and uncheck a box and enable or disable checkbox controls in MFC

What is the source code for standard checkbox actions using the Visual C ++ MFC checkbox control?

  • check the box in the displayed control
  • clear check of the displayed checkbox control
  • enable displayed check box control for user input
  • disable the displayed check box control for user input
+4
source share
2 answers

Manage checkboxes in MFC

Here's how to check, uncheck, enable and disable the 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);
+6
source

, (), CWnd:: CheckDlgButton / , :

BOOL isChecked = ...
CheckDlgButton(IDC_SOME_ID, isChecked);

/ , :

BOOL isEnabled = ...
GetDlgItem(IDC_SOME_ID)->EnableWindow(isEnabled);
+1

Source: https://habr.com/ru/post/1588998/


All Articles