1)程序一运行就Radio按钮就被选择中,只需在OnInitDialog()添加如下代码
CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1);
tb->SetCheck(1);
代表IDC_RADIO1被选中。
2)获取Radio选中的值:
先定义一个全局变量 int m_Radio;或者在class CRadioDlg : public CDialog
{
int m_Radio
}(这里的类在头文件那里的)
也是可以的;然后在Radio选择事件里面:
void CRadioDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_Radio=1;
}
void CRadioDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_Radio=2;
}
void CRadioDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
m_Radio=3;
}
void CRadioDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
m_Radio=4;
}
最后在一个获取Radio控件选择中的值,如按钮单击事件里面:
void CRadioDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str1;
CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1+m_Radio-1);
tb->GetWindowText(str1);
m_Static.SetWindowText(str1);
}
最终运行的效果图: