Visual C++ and MFC Fundamentals Chapter 20: List-Based Controls
The nIDButton argument is the identifier of the check box whose state you want to
modify. The nCheck argument is the value to apply. It can have one of the following
values:
State Value Description
BST_UN CHECKED The check mark will be completely removed
BST_ CHECKED The button will be checked
BST_INDETERMINATE A dimmed checked mark will appear in the control’s
square. If the Tri-State property is not set or the
BS_3STATE style is not applied to the control, this value
will be ignored
Here is an example that automatically sets a check box to a dimmed appearance when the
dialog box comes up:
BOOL CCheckBoxes::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CheckDlgButton(IDC_CHECK_PHYSICAL, BST_INDETERMINATE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Alternatively, to change the state of a check box, you can call the CButton::SetCheck()
and pass of the above state values. For a check box, to set a dimmed check mark, here is
an example:
BOOL CCheckBoxes::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CButton *ChkPhysical = new CButton;
ChkPhysical = reinterpret_cast<CButton *>(GetDlgItem(IDC_CHECK_PHYSICAL));
ChkPhysical->SetCheck(BST_INDETERMINATE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
To get the current state of a check box, you can call the CWnd::IsDlgButtonChecked()
method. If a check mark appears in the square box, this method will return 1. If the
square box is empty, this method returns 0. If the check box control has the BS_3STATE
style, the method can return 2 to indicate that the check mark that appears in the square
box is dimmed.