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

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - Sephil

[小技巧] 倍数的向上取整和向下取整 WTL汉化版 Delphi 与 VC 共享接口和对象 DelphiXE泛型不能用类类型做为约束的另类解决方案 百度音乐下载工具 (最后更新: 2012-7-20) 为Delphi应用增加脚本支持 插件框架Extensible Framework for Delphi DirectUI for Delphi WriteFile写磁盘扇区是87错误的原因 批量更改文件名的批处理文件 替代Windows运行功能的工具FastRun 关于 API 中返回字串的一些问题 BCB/Delphi2007 隐藏任务栏图标 OGA & WGA Crack 所有小工具 迅雷/快车/旋风地址转换器 oracle ora-01033和ora-00600错误 数独游戏 SudokuPuzzle 将文件夹映射为驱动器的工具
VC CListCtrl 第一列列宽自适应
Sephil · 2011-04-03 · via 博客园 - Sephil

今天用VC写工具的时候用到CListView,并且ListCtrl的第一列需要自动拉伸,以占满空白区域

Delphi做这个设置是很容易的,只要将Column的AutoSize设置为True就可以了

不过VC/SDK的AutoSize其实是根据Item的文本长度来自动设置Column Width,跟我的要求不符,只好自己实现了

其实很简单,就是觉得麻烦...

void CMyView::AdjustColumnWidth()
{
    RECT rc;
    CListCtrl
& list = GetListCtrl();
    CHeaderCtrl
* pHeader = list.GetHeaderCtrl();
    
if (!pHeader)
        
return;// 客户区域
    list.GetClientRect(&rc);
    
int nColCount = pHeader->GetItemCount();
    
// 去掉其他列占用的宽度
    for (int i = 1; i < nColCount; i++)
    {
        rc.right 
-= list.GetColumnWidth(i);
    }
// 去掉滚动条占用的宽度
    SCROLLBARINFO sbi;
    
if (list.GetScrollBarInfo(OBJID_VSCROLL, &sbi))
    {
        rc.right 
-= sbi.rcScrollBar.right - sbi.rcScrollBar.left;
    }
// 修改列宽
    list.SetColumnWidth(0, rc.right > rc.left ? rc.right - rc.left : LVSCW_AUTOSIZE_USEHEADER);
}

使用方法:在OnSize消息中调用一下AdjustColumnWidth就好了

void CMyView::OnSize(UINT nType, int cx, int cy)
{
    CListView::OnSize(nType, cx, cy);
if (GetListCtrl().GetSafeHwnd())
        AdjustColumnWidth();
}