VC++_6.0常用控件使用方法介绍.doc

上传人:新** 文档编号:544524855 上传时间:2023-08-24 格式:DOC 页数:6 大小:44KB
返回 下载 相关 举报
VC++_6.0常用控件使用方法介绍.doc_第1页
第1页 / 共6页
VC++_6.0常用控件使用方法介绍.doc_第2页
第2页 / 共6页
VC++_6.0常用控件使用方法介绍.doc_第3页
第3页 / 共6页
VC++_6.0常用控件使用方法介绍.doc_第4页
第4页 / 共6页
VC++_6.0常用控件使用方法介绍.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《VC++_6.0常用控件使用方法介绍.doc》由会员分享,可在线阅读,更多相关《VC++_6.0常用控件使用方法介绍.doc(6页珍藏版)》请在金锄头文库上搜索。

1、VC+ 6.0常用控件使用方法介绍*除非特别说明,本文中所用控件变量类型为Control一般控件可用/不可用EnableWindow(TRUE);EnableWindow(FALSE);1、Static Text-静态控件 -类CStatic 取值/赋值(变量类型为Control)m_lbl.GetWindowText(string);m_lbl.SetWindowText(string);2、Edit Box-编辑控件 -类CEdit 取值/赋值m_txt.GetWindowText(string);m_txt.SetWindowText(string);3、Check Box-复选控件 -

2、类CButton (1)设置选中/未选中m_chk.SetCheck(BST_CHECKED); m_chk.SetCheck(BST_UNCHECKED);(2)判断是否选中int nCur = m_chk.GetCheck();nCur取值为 BST_CHECKED/BST_UNCHECKED。4、Radio Box-单选控件 -类 CButton (1)默认选中第一项m_radio.SetCheck(BST_CHECKED);(2)选中组中任一项CWnd:CheckRadioButton void CheckRadioButton(int nIDFirstButton, int nIDL

3、astButton, int nIDCheckButton); (3)判断哪一项被选中CWnd:GetCheckedRadioButton int GetCheckedRadioButton(int nIDFirstButton, int nIDLastButton);(4)控件变量类型为Value时,可通过给int型变量赋值0、1、2.选中第1、2、3.个选项。int型变量默认值为-1,是在构造函数中赋的值。当然也可通过判断int型变量的值,知道哪一个选项被选中。5、Combo Box-组合框控件 -类CComboBox (1)风格Simple-象List Box一样显示数据Dropdown

4、-可以输入,也可以选择Drop List-只能选择(2)添加数据a.属性对话框-Data-Enter listbox items,用Ctrl+Enter换行;b.m_combo.AddString(string);c.m_combo.InsertString(index,string);(3)显示数据 设计页面,点击Combo Box Control右边的下拉箭头,显示的矩形框就是显示数据的区域。(4)设置当前选项 m_combo.SetCurSel(项索引);(5)获取当前选项int nIndex = m_combo.GetCurSel();CString str;m_combo.GetLB

5、Text(nIndex, str);注:Combo Box Control会自动排序,数据显示顺序可能与预期不同,建议添加数据时用InsertString(索引,值)。 6、List Box-列表框控件 -类CListBox (1)插入项m_list.AddString(string);(2)设置当前选择项m_list.SetCurSel(项索引);(3)获取当前选择项int nIndex = m_list.GetCurSel();m_list.GetText(nIndex, string);(4)删除一项m_list.DeleteString(项索引);(5)删除所有项m_list.Rese

6、tContent();(6)获取总项数m_list.GetCount()(7)List Box的选项前面加复选框(Check Box)a.风格声明时用类CCheckListBox代替CListBox,即CCheckListBox m_list;而不是CListBox m_list;属性对话框-Styles-Owner draw设为Fixed属性对话框-Styles-勾选Has stringsb.设置选择void SetCheck(int nIndex, int nCheck);ParametersnIndex Index of the item whose check box is to be

7、 set.nCheck State of the check box: 0 for clear, 1 for checked, and 2 for indeterminate.c.获取选择int GetCheck(int nIndex);ParametersnIndex Index of the item whose check status is to be retrieved.Return Value Zero if the item is not checked, 1 if it is checked, and 2 if it is indeterminate.7、List Contro

8、l-列表框扩展控件 -类CListCtrl (1)样式:属性对话框框-Styles-Format有4,分别是Icon/Small Icon/List/Report;(2)Report格式设置扩展风格DWORD dwStyle = m_list.GetExtendedStyle();dwStyle |= LVS_EX_FULLROWSELECT; / 选中某行使整行高亮(只适用与report风格的listctrl)dwStyle |= LVS_EX_GRIDLINES; / 网格线(只适用与report风格的listctrl)m_list.SetExtendedStyle(dwStyle);(3

9、)Report格式插入列m_list.InsertColumn(1, 列一, LVCFMT_RIGHT, 150);m_list.InsertColumn(2, 列二, LVCFMT_LEFT, 100);m_list.InsertColumn(3, 列三, LVCFMT_LEFT, 100);m_list.InsertColumn(4, 列四, LVCFMT_LEFT, 200);m_list.InsertColumn(5, ID, LVCFMT_CENTER, 0);(4)Report格式插入一行数据int nIndex = m_list.GetItemCount();m_list.Ins

10、ertItem(nIndex, s1);m_list.SetItemText(nIndex, 1, s2);m_list.SetItemText(nIndex, 2, s3);m_list.SetItemText(nIndex, 3, s4);m_list.SetItemText(nIndex, 4, s5);(5)Report格式删除所有行m_list.DeleteAllItems();(6)Report格式获取某行某列数据CString sID = m_list.GetItemText(行索引, 列索引);(7)Report格式删除选择行,多选时可用循环。POSITION pos = m_

11、list.GetFirstSelectedItemPosition();if (pos != NULL) int nIndex = m_list.GetNextSelectedItem(pos); m_list.DeleteItem(nIndex);8、Date Time Picker-日期时间控件-类CDateTimeCtrl (1)样式:属性对话框框-Styles-Format有3,分别是Short Date/Long Date/Time,分别显示短日期(2009-03-12)/长日期(2009年3月12日)/时间(20:08:06),日期格式默认有一向下箭头,时间格式默认有一Spin C

12、ontrol;(2)可编程设置其显示格式,例如年4位,月、日、时、分、秒2位,CString formatStr= _T(yyyy-MM-dd);m_txtDate.SetFormat(formatStr);formatStr= _T(HH:mm:ss);m_txtTime.SetFormat(formatStr);(3)取值赋给CStringm_txtDate.GetWindowText(sAddDate);m_txtTime.GetWindowText(sAddTime);9、Spin-旋转按钮控件 -类CSpinButtonCtrl (1)与Edit控件关联首先,排列控件的Tab键顺序,

13、要让Spin Control的Tab Order紧跟着Edit Control(就是说,Spin Control的Tab Order是Edit Control的Tab Order加1);设置tab order 的方法是 Ctrl+d,然后用鼠标挨个点击,就是按TAB键时焦点在窗体上的移动顺序; 然后,Spin Control属性对话框中勾选Auto buddy和Set buddy integer。(2)设置上下限m_spin.SetRange(1, 60);(3)设置当前值,可以不用给Edit控件赋值m_spin.SetPos(3);(4)获取当前值int nCur = m_spin.GetP

14、os();10、Slider-滑动条控件-类CSliderCtrl (1)设置上下限、最小滑动值m_slider.SetRange(5,100);m_slider.SetTicFreq(1);(2)设置/获取当前值m_slider.SetPos(nCur);int nCur = m_slider.GetPos();(3)背景色:重写OnCtlColor(),虽然不知道Slider属于nCtlColor的哪一类,但试验表明似乎是属于CTLCOLOR_STATIC。HBRUSH CDlgOptionVideo:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) HBRUSH hbr = CDialog:OnCtlColor(pDC, pWnd, nCtlColor); / TODO: Change any attributes of the DC here / 设置透明背景模式 pDC-SetBkMode(TRANSPARENT); / TODO: Return a different brush if the default is not desired switch(nCtlColor) / 设置背景刷子为空

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号