惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - gxh973121

Windbg在Managed App中设置函数断点的几种方法 TeamTalk---服务端架构 找不到资产文件 project.assets.json windows 2008 VPN(PPTP/L2TP)搭建 - gxh973121 vs 调试时 QuickWatch 不能计算变量值 wireshark 分析过滤数据 go module 设置 逻辑漏洞之支付漏洞 java holdsLock()方法检测一个线程是否拥有锁 c#编程指南(十) 平台调用P-INVOKE完全掌握, 字符串和指针 Git过滤文件和文夹 WideCharToMultiByte和MultiByteToWideChar函数的用法 c++ 时间类型详解 time_t 链接报error LNK2019: unresolved external symbol错误,解决 VS2008 工程只生成dll不生成lib的解决方案 vs2010中的MSBuild输出warning MSB8012问题 在VS2010下编译和使用tesseract_ocr识别验证码 tesseract-ocr 提高验证码识别率手段之---识别码库训练方法 Windows下Qt5搭建Android开发环境笔记
VC CComboBox用法总结
gxh973121 · 2014-08-29 · via 博客园 - gxh973121

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 
    00// 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);