Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals
check box, its style must include the BS_CHECKBOX style. If you want the control to
display or hide a check mark when it gets clicked, create it with the
BS_AUTOCHECKBOX style.
BOOL CCheckBoxes::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CButton *chkDay[5];
chkDay[0] = new CButton;
chkDay[0]->Create("&Monday", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | BS_LEFTTEXT,
CRect(20, 40, 140, 55), this, 0x11);
chkDay[1] = new CButton;
chkDay[1]->Create("&Tuesday", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | BS_LEFTTEXT,
CRect(20, 60, 140, 75), this, 0x12);
chkDay[2] = new CButton;
chkDay[2]->Create("&Wednesday", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | BS_LEFTTEXT,
CRect(20, 80, 140, 95), this, 0x13);
chkDay[3] = new CButton;
chkDay[3]->Create("&Thursday", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | BS_LEFTTEXT,
CRect(20, 100, 140, 115), this, 0x14);
chkDay[4] = new CButton;
chkDay[4]->Create("&Friday", WS_CHILD | WS_VISIBLE |
BS_AUTOCHECKBOX | BS_LEFTTEXT,
CRect(20, 120, 140, 135), this, 0x15);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
We mentioned already that a check box can assume one of three states: checked,
unchecked, or dimmed. If you want to apply one of the states to such a check box, that is,
to programmatically check, uncheck, or dim it, you can call the
CWnd::CheckDlgButton() method whose syntax is:
void CheckDlgButton( int nIDButton, UINT nCheck );