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. 自定义TextField清除按钮

    当需要设置TextField的清除按钮的时候,系统的总是不满足需求,这就需要我们自定义了,代码如下: // // TextFieldDemoViewController.m // OCDemo // ...

  2. xtrareport实现指定记录数以及填补空白行(网上整理)

    在Detail的事件中: int i=0; private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventAr ...

  3. 被忽略的js细节

    今天在写一个程序,出了一点小bug,找了许久许久,终于把问题给揪了出来,真相大白那一刻感觉好蛋疼--深刻体会到了语言之间的差异. <script type="text/javascri ...

  4. RedHat 6.7 Enterprise x64环境下使用RHCS部署Oracle 11g R2双机HA

    环境 软硬件环境 硬件环境: 浪潮英信服务器NF570M3两台,华为OceanStor 18500存储一台,以太网交换机两台,光纤交换机两台. 软件环境: 操作系统:Redhat Enterprise ...

  5. Windows XP SP3 VC6环境下成功编译openssl-0.9.8zh

    1.下载openssl-0.9.8zh解压到f:\openssl-0.9.8zh 下载nasm-2.12.03rc1解压到D:\develop\nasm-2.12.03rc1并把添加到系统环境变量PA ...

  6. angular报$injector / unpr的错误

    原因:angular引用未定义的错误,因为JS代码压缩过后找不到申明的变量,,没在使用之前定义,且代码被压缩,则报错(变量压缩后会变成单个字母无法识别,需在引用前分别定义): 解决:angular.m ...

  7. python学习笔记-多进程

    multiprocessing from multiprocessing import Process import time def f(name): time.sleep(2) print('he ...

  8. CDN系统对网站的性能有极大的提升

    CDN系统对网站的性能有极大的提升 打开一个网站 我们只是请求了一个页面.单个页面,实际上所有文件都是一个新的请求.以新浪为例一共发起了35个请求. 这35个请求中.只有一个动态内容.其它均为静态.这 ...

  9. Spring bean的作用域和生命周期

    bean的作用域 1.singleton,prototype, web环境下:request,session,gloab session 2.通过scope="" 来进行配置 3. ...

  10. python python 入门学习之网页数据爬虫cnbeta文章保存

    需求驱动学习的动力. 因为我们单位上不了外网所以读新闻是那么的痛苦,试着自己抓取网页保存下来,然后离线阅读.今天抓取的是cnbeta科技新闻,抓取地址是http://m.cnbeta.com/wap/ ...