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 ...
随机推荐
- Spring——(一)IoC
1. 什么是IOC IOC:inversion of Control 控制反转. 控制反转:即控制权由应用程序代码转到了外部容器.(反转:就是控制权的转移).--降低业务对象之间的依赖程度,即实现了解 ...
- SQL基本语句以及示例
基本语句: /*dorp colunm*/ 语法:ALTER TABLE 表名 DROP COLUMN 要删除的字段 验证财务转换的正确性,查询以下两个表是否有数据 /*表连接inner jion ...
- CODE[VS] 1230 元素查找
1.题目戳这里 2.代码: #include<iostream> #include<algorithm> using namespace std; int n,m,a[1000 ...
- SAP 创建物料主数据分类视图特性
1.CL01创建物料分类 2.去CT04中去创建特性值 创建完成之后保存, 3.创建物料的分类视图,选择相应的特性值
- Centos7.0安装配置PHP7.0
YUM安装所需开发包 yum install wget make gcc gcc-c++ bison autoconf patch \ pcre-devel zlib-devel openssl-de ...
- Quartz.net 定式调度任务
再用Quartz 做任务调度作业时,有以下步骤: ISchedulerFactory schedFact = new StdSchedulerFactory(); IScheduler _sched; ...
- 我眼中的项目leader
个人觉得项目leader应该具备一下基础: 1.技术能力 2.领导能力 3.过滤产品不合理需求能力 4.项目周期把控能力
- 安装odoo服务
sysv init 服务 从 odoo 源码 debian 目录 拷贝 init 至 /etc/init.d/ 并 更名为 odoo cd /opt/odoo sudo cp /opt/odoo/de ...
- <head></head>
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8&qu ...
- 一个Email
Email 1.接受表单数据并用单独变量保存起来,判断用户协议,这个是必须同意的.2.判断验证码,利用验证码类Captcha.3.判断用户名,密码,邮箱规则,利用Verify类验证.4.判断唯一性,邮 ...