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 ...
随机推荐
- cinder节点部署
其实看基础理论篇大家也可以看出来,cinder跟nova流程比较像,是这样的,nova为云主机提供了虚拟资源,cinder则是提供存储相关的资源,cinder的小伙伴叫swift,不过这个一般没人用了 ...
- Flash Builder 调试器无法连接到正在运行的应用程序(57%)
Flash Builder 调试器无法连接到正在运行的应用程序(57%),可能原因: 1,flashplayer不是debug版. 2,调试器(用debug版flashplayer随便 ...
- JavaScript的继承
原型继承的实现 1 简化版本 function SuperClass(){...} function SubClass(){...} SubClass.prototype=new SuperClass ...
- js获取get方式传递的参数
String.prototype.GetValue= function(parm) { var reg = new RegExp("(^|&)"+ parm +" ...
- JavaWeb 学习0010-今日问题 2016-12-3
2016-12-3 1. 今天要做的第一个问题就是,怎么把网页变得好看点: addStudent/listStudent页面都有改动 其中 list页面还有了<c:if 的语句这是还没练习过得知 ...
- Java重点之小白解析--浅谈数据流形式图片上载
文档上载,上载也不知道哪个大神(混球)起的名字,读起来怪怪的,反正平时我只读上传. 闲话少说,直入主题.先等等这两天做文件上传,都快把宝宝折磨疯了,不会呀,各种查呀,最可悲的是废了老大功夫学会了传送文 ...
- jQuery Mobile 可折叠
可折叠的内容块 可折叠(Collapsibles)允许您隐藏或显示内容 - 对于存储部分信息很有用. 如需创建可折叠的内容块,请向某个容器分配 data-role="collapsible& ...
- solr安装笔记与定时器任务
一:solr启动 目前solr最高版本为5.5.0版本,很多solr安装都是说将server文件copy到tomcat中,但是solr版本自带有jetty的启动方式 首先下载solr-5.5.0版本, ...
- 【转】Linux学习之路--启动VNC服务
我的Linux是Fedora 13,安装方法如下: 1.打开终端,执行 # yum install -y tigervnc tigervnc-server 2.编辑/etc/sysconfi/vncs ...
- grunt配置太复杂?使用Qbuild进行文件合并、压缩、格式化等处理
上次简单介绍了下Qbuild的特点和配置,其实实现一个自动化工具并不复杂,往简单里说,无非就是筛选文件和处理文件.但Qbuild的源码也并不少,还是做了不少工作的. 1. 引入了插件机制.在Qbuil ...