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用法总结的更多相关文章

  1. VC:CString用法整理(转载)

    1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值:否则返回0. 说明:此成员函数用来测试一个CString ...

  2. VC++ GetSafeHwnd用法

    GetSafeHwnd HWND GetSafeHwnd() const; 当我们想得到一个窗口对象(CWnd的派生对象)指针的句柄(HWND)时,最安全的方法是使用GetSafeHwnd()函数. ...

  3. C++ 学习资料搜寻与学习(第一期)(未完待续)

    一.图形图像类 [Visual C++]vs2008/2005正确打开vs2010所创建项目的几种方法 jlins 2012-04-12 14:38 [Visual C++]关于无法打开包括文件:“S ...

  4. Vc++ 控件用法总结之List Control

    1.新建对话框MFC,在对话框上放一个ListCtrl ID:IDC_PATH View:Report 2.为ListCtrl添加变量 右击->添加变量m_wndPath 3.找到OnInitD ...

  5. VC中TRACE()的用法

    个人总结:最近看网络编程是碰到了TRACE语句,不知道在哪里输出,查了一晚上资料也没找出来,今天终于在CSDN上找到了,真是个高地方啊,方法如下: 1.在MFC中加入TRACE语句 2.在TOOLS- ...

  6. VC++定义全局变量及extern用法

    基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义.此外extern也可用来进行链接指定. 也就是说extern有两 ...

  7. VC中TRACE ASSERT VERIFY之用法

    一.TRACE宏     当选择了Debug目标,并且afxTraceEnabled变量被置为TRUE时,TRACE宏也就随之被激活了.但在程序的Release版本中,它们是被完全禁止的.下面是一个典 ...

  8. 【转】VC中MessageBox与AfxMessageBox用法与区别

    原文网址:http://blog.csdn.net/holybin/article/details/28403109 一.MessageBox()用法 1.函数原型 Messagebox函数在Win3 ...

  9. VC/MFC中的CComboBox控件使用详解

    CComboBox控件详解 CComboBox控件又称作组合框控件,其有三种形态可供选择,1.简单组合框(Simple)2.下拉组合框(Drop-down)3.下拉列表式组合框(Drop-down l ...

随机推荐

  1. oracle分页查询sql

    select * from( select shopid,rownum rn from p_shopinfo where is_hot=1 and rownum <=6 order by sho ...

  2. NGUI 屏幕自适应大屏与小屏(初始设定宽高为1280x720,能适应比其小或者更大的屏)

    具体细节可以参考另外一篇随笔! 以下提供的算法完成的事: 1.自适应1280x720分辨率以下的屏幕 2.自适应1280x720分辨率以上的屏幕 在我设定的要求内包括的分辨率大部分都测过了,背景图.全 ...

  3. (转)如何在一台电脑上开启多个tomcat 和配置让系统识别哪个具体的tomcat

    大家基本上都只在一台电脑上面启动一个Tomcat,而启动多个Tomcat会提示报错等相关故障.而假如调试负载均衡及集群的时候,需要在一台电脑上面开启多个Tomcat,那么怎么开启呢? 方法/步骤 首先 ...

  4. Android ActionBar

    ActionBar 在android3.0中就加入了,但是android3.0适用于平板电脑的,在手机不能使用.android 4.0之后也开始有AndroidBar.所以说要想使用androidBa ...

  5. $http服务和$location

    1.angular的$http服务跟jquery中的ajax很类似,用法如下: $http({ method : 'GET', url : 'data.php' }).success(function ...

  6. MySQL安装之后没有MySQL数据库的原因

    mysql安装完之后,登陆后发现只有两个数据库:mysql> show databases;+--------------------+| Database           |+------ ...

  7. call_user_function()方法的使用

    call_user_func ( callback $function [, mixed $parameter [, mixed $... ]] ) 调用第一个参数所提供的用户自定义的函数. 返回值: ...

  8. linux 定时清理session

    php session 运营想让用户登陆网站就能永久保持登陆会话,感觉这是扯淡,因为视频播放1小时,所以我设置了两小时过期. 但是用户过多,导致session文件大量存储.产生上百万千万.服务器空间很 ...

  9. Spring.Scheduling.Quartz 作业的应用(定时任务和循环触发任务)

    .定时任务的实现,比如有个任务是要晚上2点10分的时候要去触发的,先定义这个任务类RskBookFilterInitDiningService.cs,这里其实有两种实现,一种是需要继承QuartzJo ...

  10. 无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器。 (Microsoft SQL Server,错误: 20582)

    无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器. (Microsoft SQL Server,错误: 20582) 2013-01-05 15:02 478 ...