Radio Button成组使用时,只需保证在添加控件时资源号连续,并且第一个Radio Button的属性中Group被选中即可.,比如:
IDC_RADIO1,IDC_RADIO2,IDC_RADIO3,IDC_RADIO3,IDC_RADIO4;
1,2为一组,3,4为一组则将1,3的Group选中即可。
1.设定Radio为 选中状态 :(CButton*)GetDlgItem(ID号))->SetCheck(TRUE);(SetCheck(FALSE)) 为不选中,如果想初始化为选中状态,则在InitDlg函数中加入此函数.
( (CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);
注:每一组只能有一个被选中,如:1,2一组,1被选中时,2则不能被选中
2.检查Radio是否为选中状态,可用GetCheck()函数,如:
if(BST_CHECKED==((CButton*)GetDlgItem(IDC_RADIO1))->GetCheck())
//选中;
if(BST_UNCHECKED==((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck())
//未选中;
实际程序跑不起来,修改如下:
CButton btn;
btn.Attach(GetDlgItem(IDC_RADIO1) );
btn.SetCheck(TRUE);