1.创建关联变量,并给初始值
在BOOL CDialogDlg::OnInitDialog()中创建关联,并给默认值
//给复选框创建关联变量,并给默认值 pCheck1 = (CButton*)GetDlgItem(IDC_CHECK1); pCheck2 = (CButton*)GetDlgItem(IDC_CHECK2); pCheck3 = (CButton*)GetDlgItem(IDC_CHECK3); pCheck4 = (CButton*)GetDlgItem(IDC_CHECK4); pCheck1->SetCheck(1);
2.读取复选框的状态
//复选框 void CDialogDlg::OnButton2() { // TODO: Add your control notification handler code here CString str; m_CheckState = 0; m_CheckState += pCheck1->GetCheck(); m_CheckState +=(pCheck2->GetCheck()); m_CheckState +=(pCheck3->GetCheck()); m_CheckState +=(pCheck4->GetCheck()); str = '0'+m_CheckState; MessageBox(str); }