VC++ MFC CheckBox

MFC中复选框CheckBox的基类是CButton! 

得到复选框状态的函数:CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK_MIXI);

           int state = pBtn->GetCheck();

           当state == 0时表示该复选框没有被选中;

           当state == 1时表示该复选框被选中;

           当state == 2时表示不确定(applies only if the button has the BS_3STATE or BS_AUTO3STATE style);

设置复选框状态的函数:CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK_MIXI);

           pBtn->SetCheck(1);

           SetCheck(1)表示设置复选框为“选中”状态;

           SetCheck(0)表示设置复选框为“未选中”状态;

           SetCheck(2)设置复选框为不确定状态(This value can be used only if the button has the BS_3STATE or BS_AUTO3STATE style.);

注:非0也为“选中”。

勾选:全部选择,取消勾选:全部选择.

void CFurtherConvertCutCodeView::OnClickedCheckSelectall()
{	
	// TODO: Add your control notification handler code here
	if(BST_CHECKED==!IsDlgButtonChecked(IDC_CHECK_SelectAll))
	{
	
		SelectCheckList(0);
	}
	else
	{		
		SelectCheckList(1);
	}
}

void CFurtherConvertCutCodeView::SelectCheckList(int nCheck)
{
	int iSel=m_ListFiles.GetCount();
	for(int i=0;i<iSel;i++)
	{
	   m_ListFiles.SetCheck(i,nCheck);

	}
}
原文地址:https://www.cnblogs.com/ike_li/p/2852826.html