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 ...
随机推荐
- iOS错误总结(三)
1.如果tableView设置为分组的样式(默认是有cell之间的分割线,可以设置颜色),默认有组以及组尾的高度 需要手动在组头组尾的代理方法中进行组高的设置(如果想设置为0,最好写0.01) 2.组 ...
- (转)java中静态代码块的用法 static用法详解
一)java 静态代码块 静态方法区别一般情况下,如果有些代码必须在项目启动的时候就执行的时候,需要使用静态代码块,这种代码是主动执行的;需要在项目启动的时候就初始化,在不创建对象的情况下,其他程序来 ...
- ABP mapto 映射
obj1.MapTo(obj2); obj1=>obj2: 在obj1实体里添加映射 [AutoMap(typeof(obj2))] public class obj1 { }
- Gradle笔记系列(二)
1.使用Gradle命令行 在这篇博客中,我们将简要介绍Gradle命令行的使用. 1.1 执行多任务 通过在命令行列出每个任务(task),你可以在一次构建(build)中执行多个任务.例如,命令g ...
- MAVEN解决Cannot change version of project facet Dynamic web module to 2.5
我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一 ...
- Nodejs Express下引入本地文件的方法
Express的结构如下: |---node_modules------用于安装本地模块. |---public------------用于存放用户可以下载到的文件,比如图片.脚本文件.样式表 ...
- XE3随笔21:系统默认语言与系统支持的语言列表
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- ansible-playbook
一.ansible-playbook介绍: playbook是由一个或多个"play"组成的列表.play的主要功能在于将事先归为一组的主机装扮成事先通过ansible中的task ...
- mac上的git completion
只安装bash-completion,是没有git补全的,因为此时/usr/local/etc/bash-completion.d/下面没有git-XXX.sh 解决方法是brew install g ...
- Keras Installation
#Install numpy and scipy sudo apt-get install gfortran libopenblas-dev liblapack-dev libatlas-base-d ...