VC CComboBox用法总结
VC每日一练,虽然简单,不动手试一下不能真正记住。
大气象
CComboBox *comboBox=(CComboBox*)GetDlgItem(IDC_COMBO1);
comboBox->InsertString(0,_T("9:30 "));
comboBox->InsertString(1, _T("10:30 "));
comboBox->SetCurSel(1); //设置选中的项
//取得选中的值
CString selStr;
int nIndex = comboBox->GetCurSel();//取得选中的索引
comboBox->GetLBText(nIndex,selStr);
MessageBox(selStr);
默认ComboBox显示一个很短的下拉框,很不方便。这里有个函数,可以让你设置下拉列表的高度,很方便。
先在头文件中声明:
public:
void set_DropDownSize(CComboBox& box, UINT LinesToDisplay);
再在源文件中定义:
大气象 void CMySdiView::set_DropDownSize(CComboBox& box, UINT LinesToDisplay)
/*--------------------------------------------------------------------------
* Purpose: Set the proper number of lines in a drop-down list or
* combo box.
* Description: Resizes the combo box window to fit the proper number
* of lines. The window must exist before calling this function.
* This function should be called when the combo box is created, and when
* the font of the combo box changes. (e.g. WM_SETTINGCHANGE)
* Testing needed:
* Are there cases where SM_CYBORDER should be used instead of SM_CYEDGE?
* owner-draw variable height combo box
* Subclassed combo box with horizontal scroll-bar
* Returns: nothing
* Author: KTM
*--------------------------------------------------------------------------*/
{
ASSERT(IsWindow(box)); // Window must exist or SetWindowPos won't work CRect cbSize; // current size of combo box
int Height; // new height for drop-down portion of combo box box.GetClientRect(cbSize);
Height = box.GetItemHeight(-1); // start with size of the edit-box portion
Height += box.GetItemHeight(0) * LinesToDisplay; // add height of lines of text // Note: The use of SM_CYEDGE assumes that we're using Windows '95
// Now add on the height of the border of the edit box
Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges // The height of the border of the drop-down box
Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges // now set the size of the window
box.SetWindowPos(NULL, // not relative to any other windows
0, 0, // TopLeft corner doesn't change
cbSize.right, Height, // existing width, new height
SWP_NOMOVE | SWP_NOZORDER // don't move box or change z-ordering.
);
}
再在OnInitialUpdate()函数中调用:
CComboBox *comboBox=(CComboBox*)GetDlgItem(IDC_COMBO1);
set_DropDownSize(*comboBox,5);// 第二个参数决定高度是显示几行
UpdateData(false);
VC CComboBox用法总结的更多相关文章
- VC:CString用法整理(转载)
1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值:否则返回0. 说明:此成员函数用来测试一个CString ...
- VC++ GetSafeHwnd用法
GetSafeHwnd HWND GetSafeHwnd() const; 当我们想得到一个窗口对象(CWnd的派生对象)指针的句柄(HWND)时,最安全的方法是使用GetSafeHwnd()函数. ...
- C++ 学习资料搜寻与学习(第一期)(未完待续)
一.图形图像类 [Visual C++]vs2008/2005正确打开vs2010所创建项目的几种方法 jlins 2012-04-12 14:38 [Visual C++]关于无法打开包括文件:“S ...
- Vc++ 控件用法总结之List Control
1.新建对话框MFC,在对话框上放一个ListCtrl ID:IDC_PATH View:Report 2.为ListCtrl添加变量 右击->添加变量m_wndPath 3.找到OnInitD ...
- VC中TRACE()的用法
个人总结:最近看网络编程是碰到了TRACE语句,不知道在哪里输出,查了一晚上资料也没找出来,今天终于在CSDN上找到了,真是个高地方啊,方法如下: 1.在MFC中加入TRACE语句 2.在TOOLS- ...
- VC++定义全局变量及extern用法
基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义.此外extern也可用来进行链接指定. 也就是说extern有两 ...
- VC中TRACE ASSERT VERIFY之用法
一.TRACE宏 当选择了Debug目标,并且afxTraceEnabled变量被置为TRUE时,TRACE宏也就随之被激活了.但在程序的Release版本中,它们是被完全禁止的.下面是一个典 ...
- 【转】VC中MessageBox与AfxMessageBox用法与区别
原文网址:http://blog.csdn.net/holybin/article/details/28403109 一.MessageBox()用法 1.函数原型 Messagebox函数在Win3 ...
- VC/MFC中的CComboBox控件使用详解
CComboBox控件详解 CComboBox控件又称作组合框控件,其有三种形态可供选择,1.简单组合框(Simple)2.下拉组合框(Drop-down)3.下拉列表式组合框(Drop-down l ...
随机推荐
- [整理]S-Record数据格式解析
S-Reord是一种由摩托罗拉公司创建的文件格式(不得不说,摩托罗拉厉害啊,SPI和S-Record都是他们创造的).S-Record的基本字符为ASCII字符,用以表示相应的十六进制数据.该数据格式 ...
- python初学day01
1.执行Python脚本时打印的字符有颜色 1. print "\033[32;1mhello\033[0m" #打印绿色 2. print "\033[31;1mhel ...
- python 自动发邮件 Errno61 Connection refused
此问题是在mac机器上遇到 之前在windows平台运行ok的脚本在mac上报错 后来查了半天 发现是网络接入不对 切换下网络后问题就解决了
- asp.net web api集成微信服务(使用Senparc微信SDK)
/// <summary> /// 微信请求转发控制器 /// </summary> [RoutePrefix("weixin")] public clas ...
- JavaScript中关于时间的知识点
1.计算时间差,天数,小时数,余数 var begintime_ms = Date.parse(new Date(begintime.replace(/-/g, "/"))); / ...
- CSS里常见的块级元素和行内元素
根据CSS规范的规定,每一个网页元素都有一个display属性,用于确定该元素的类型,每一个元素都有默认的display属性值,比如div元素,它的默认display属性值为“block”,成为“块级 ...
- X-UA-Compatible失效问题
有时候发现页面中写了<meta http-equiv="X-UA-Compatible" content="IE=8" />,但是文档模式依旧没改变 ...
- MMS源码中异步处理简析
1,信息数据的查询,删除使用AsycnQueryHandler处理 AsycnQueryHandler继承了Handler public abstract class AsyncQueryHandle ...
- 大前端学习笔记整理【六】this关键字详解
前言 在上一篇博客里我总结了下辨认this指向的四种方式,但是有师兄抛出一个问题来,我发现那些this的指向并不能说明更复杂的情况,先看下这段代码 var a = { name: 'a', getNa ...
- Missing separate debuginfos
问题:Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64解决:1.将/etc/yum.rep ...