MFC界面(二)Radio Button 单选框

来源:互联网 发布:linux oracle 安装 编辑:程序博客网 时间:2024/06/13 18:20

重要函数CheckRadioButton

函数功能:该函数给一组单选按钮中的一个指定按钮加上选中标志,并且清除组中其他按钮的选中标志。   

函数原型:BOOL CheckRadioButtonHWND hDlg, int nlDFirstButton, int nlDLastBUtton, int nlDCheckButton);   

参数:   

hDlg:指向包含单选按钮的对话框的句柄。   

nlDFirstButton:指定组中第1个单选按钮的标识符。   

nlDLastButton:指定组中最后一个单选按组的标识符。   

nlDCheckButton:指出要选中的那个单选按钮的标识符。   

返回值:如果函数执行成功,返回值非零;如果失败,则返回零。若想获取更多错误信息,请调用GetLastError函数。

BOOL xxxxxDlg::OnInitDialog()中加入

// TODO: Add extra initialization here

CheckRadioButton(IDC_RADIO1, IDC_RADIO5, IDC_RADIO3);

////////////////////////////////////////////////////////////////////////

重要函数CheckRadioButton

 函数功能:在给定的一组单选框ID中获得当前被选中的单选按钮的ID   

函数原型:int GetCheckedRadioButton( int nIDFirstButton, int nIDLastButton );   

返回值: 当有被选中的单选框时返回被选中的单选框的ID ,如果所给的组中都没被选中则返回  

参数:   

nIDFirstButton 单选框组中第一个整形值的ID   

nIDLastButton 单选框组中最后一个整形值ID 

定义变量获得当前所选的按钮

int nID = GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO5);