1、新建一个基于对话框的应用程序,应用程序名称为CBaseButton。
2、对对话框进行如下图的设计,添加二个Group Box控件、三个Radio Button控件、四个Check Box控件,两个按钮,两个文本框。
3、双击提交选择按钮,为其添加响应函数OnCheckin(),并添加一下代码:void CCBaseButtonDlg::OnCheckin(){ // TODO: Add your control notification handler code here GetDlgItem(ID_RESET)->EnableWindow(true); //重新选择有效 GetDlgItem(ID_CHECKIN)->EnableWindow(false); //提交按钮无效 UpdateData(true); m_show="内存: "; //保存输出消息字符串 CString str; switch(m_radio) { case 0: //该组第一个单选项被选中 GetDlgItemText(IDC_RADIO1,str); m_show=m_show+str; break; case 1: //该组第二个单选项被选中 GetDlgItemText(IDC_RADIO2,str); m_show=m_show+str; break; case 2: //该组第三个单选项被选中 GetDlgItemText(IDC_RADIO3,str); m_show=m_show+str; break; } if(m_check1.GetCheck()==1) //复选框1被选中 { GetDlgItemText(IDC_CHECK1,str); m_show=m_show+str; } if(m_check2.GetCheck()==1) //复选框2被选中 { GetDlgItemText(IDC_CHECK2,str); m_show=m_show+str; } if(m_check3.GetCheck()==1) //复选框3被选中 { GetDlgItemText(IDC_CHECK3,str); m_show=m_show+str; } if(m_check4.GetCheck()==1) //复选框4被选中 { GetDlgItemText(IDC_CHECK4,str); m_show=m_show+str; } UpdateData(false);}
4、双击重新选择按钮,为其添加响应函数OnReset(),并添加一下代码:void CCBaseButtonDl爿讥旌护g::OnReset(){ // TODO: Add your control notification handler code here GetDlgItem(ID_RESET)->EnableWindow(false); //重新选择按钮无效 GetDlgItem(ID_CHECKIN)->EnableWindow(true); //提交选择按钮有效 m_radio=1; //单选框的默认值 m_check1.SetCheck(0); //复选框1不选中 m_check2.SetCheck(0); //复选框2不选中 m_check3.SetCheck(0); //复选框3不选中 m_check4.SetCheck(0); //复选框4不选中 m_show=""; UpdateData(false);}
5、程序运行如下选择8G内存和无线鼠标、无线键盘