MFC-combox和listbox、radio button、group box等控件及onTimer函数的应用
来源:互联网 发布:章鱼彩票 知乎 编辑:程序博客网 时间:2024/06/16 13:02
combox、listbox控件内容添加:
控件访问方式:
CEdit* editBox = (CEdit*)GetDlgItem(ID);CString str;editBox->GetWindowText(str);int checkRadio = GetCheckedRadioButton(ID_RADIO1, ID_RADIO3);switch (checkRadio){case ID_RADIO1:{ CListBox* listBox = (CListBox*)GetDlgItem(ID_LIST1); if (listBox->FindStringExact(0, str)**IB_ERR) listBox->AddString(str);}break;case ID_RADIO2:{ CComboBox* comboBox = (CComboBox*)GetDlgItem(IDC_COMBO1); if (comboBox->FindStringExact(0, str)**IB_ERR) comboBox->AddString(str);}break;case ID_RADIO3:{ CListBox* listBox = (CListBox*)GetDlgItem(ID_LIST1); if (listBox->FindStringExact(0, str)**IB_ERR) listBox->AddString(str); CComboBox* comboBox = (CComboBox*)GetDlgItem(IDC_COMBO1); if (comboBox->FindStringExact(0, str)**IB_ERR) comboBox->AddString(str);}break;}
一、Radio button的使用:
groupbox里面选择:radio button。如果要让radio button仅在当前group box里面起作用,需要将group box的Group属性设置为True。
((CButton*)GetDlgItem(IDC_RADIO_HOME_1))->SetCheck(TRUE);((CButton*)GetDlgItem(IDC_RADIO_LOWSP))->SetCheck(TRUE);检查某一项radio是否被选中:
WORD check = ((CButton*)GetDlgItem(IDC_RADIO_HOME_1))->GetCheck();WORD check2 = ((CButton*)GetDlgItem(IDC_RADIO_HIGHSP))->GetCheck();
检查一个group box里面的radio哪个被选中
WORD check = ((CButton*)GetDlgItem(IDC_RADIO_HOME_1))->GetCheck();
(check之前需保证在一个group box里面的radio button的IDC连续):
Ctrl+D查看控件的Tab顺序,第一次点击,即设置控件的序号为1,然后可以依次点击,给控件编号。若想临时更改序号,可如下操作。例如像修改控件XXX的序号为4,则按照Ctrl键点击序号为3的控件,然后松开Ctrl键,再点击控件A即修改控件A的序号为4。
CString str;UINT nCheckID = GetCheckedRadioButton(IDC_RADIO_HOME_1, IDC_RADIO_HOME_BACK);switch (nCheckID){case IDC_RADIO_HOME_1:str = "一次回零";break;case IDC_RADIO_HOME_2:str = "二次回零";break;case IDC_RADIO_HOME_BACK:str = "一次回零+反找";break;}
二、在combox里面添加string的办法:
给控件关联一个CComBox类型的控件变量,如comBox,然后用如下语句为其添加string
//.h文件里面定义变量CComBox comBox//在cpp文件里的初始化函数中添加Cstring strP="正";Cstring strP="负";comBox->AddString(strP);comBox->AddString(strN);
//默认选中正方向
comBox->SetCurSel(0);
或者:
CComboBox* comboBox = (CComboBox*)GetDlgItem(IDC_COMBO_X);CString str = "负";comboBox->AddString(str);str = "正";comboBox->AddString(str);str = "正负";comboBox->AddString(str);comboBox->SetCurSel(1);
检查comBox里面的哪一项被选中:
WORD com =((CComboBox*)GetDlgItem(IDC_COMBO_X))->GetCurSel();返回值为CComBox里面各个条目的索引号。
</pre>三、Timer函数用于定时(固定周期)刷新。实现如下:<p></p><p>1、在对话框属性中添加消息函数:WM_TIMER</p><p><img src="http://img.blog.csdn.net/20160704141243151" alt="" /></p><p></p><pre code_snippet_id="1740737" snippet_file_name="blog_20160704_12_8690826" name="code" class="cpp">void CcomboxDlg::OnTimer(UINT_PTR nIDEvent){// TODO: 在此添加消息处理程序代码和/或调用默认值CString string;//char * asctime(const struct tm *);string.Format("当前时间: %d", a++);GetDlgItem(IDC_STATUS)->SetWindowText(string);CDialogEx::OnTimer(nIDEvent);}2、在Resource.h文件中添加
#define IDC_TIMER 99
3、在初始化函数中添加如下语句
SetTimer(IDC_TIMER, 100, NULL);
4、在对话框属性中添加WM_DESTROY函数
并添加如下代码,在窗口关闭时销毁计数器
区别;updateData刷新整个屏幕的控件变量,输入UpdateData(FALSE),输出UpdateData(TRUE)
void CcomboxDlg::OnDestroy(){KillTimer(IDC_TIMER);CDialogEx::OnDestroy();// TODO: 在此处添加消息处理程序代码}
实例程序见资源:
http://download.csdn.net/detail/bettyshasha/9566936
效果图:
如果要让radio button仅在当前group box里面起作用,需要将group box的Group属性设置为True。
0 0
- MFC-combox和listbox、radio button、group box等控件及onTimer函数的应用
- MFC Radio Button 和 Combox Button的简单操作
- MFC对话框中改变对话框,Group Box, Static Text, Check Box, Edit Ctrl(disabled), Combo Box(disabled), Radio Button等控件背景色
- mfc 对话框 toolBox 中的控件 combo box和Radio Button
- VS2010/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2010/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2010/MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2013/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- C++ MFC / VS2013 之二十(常用控件:按钮控件Button、Radio Button和Check Box)
- MFC 控件Radio Button的使用 .
- MFC控件使用说明(combo box Button Check Box Radio Button List Control Edit Box Hot Key IP Address....)
- MFC控件使用说明(combo box Button Check Box Radio Button List Control Edit Box Hot Key IP Address)
- MFC控件使用说明(combo box Button Check Box Radio Button List Control Edit Box Hot Key IP Address....)
- MFC控件使用说明(combo box Button Check Box Radio Button List Control Edit Box Hot Key IP Address....)
- MFC控件使用说明(combo box Button Check Box Radio Button List Control Edit Box Hot Key IP Address....)
- MFC--按钮(radio button,check box)
- MFC Radio Button控件编程
- MFC Radio Button控件编程
- Energy Conversion and Management (ECM) 的审稿周期
- STL提取参数模版的类型
- 硬币问题
- 浏览器开发人员工具使用初步图解
- 贪心算法-会场安排
- MFC-combox和listbox、radio button、group box等控件及onTimer函数的应用
- linux panic分析
- WebService
- Zabbix 安装部署
- 矩阵游戏(二分图匹配)
- dnw在linux下的安装方法
- GCD学习 - swift GCD使用指南
- excel-vba组内离均差
- Cadence基础知识1(CADENCE从原理图到PCB步骤 )