ListBox_MultiColumn

本文介绍如何使用LB_SETTABSTOPS消息为ListBox设置制表位,并通过示例代码展示如何添加带有制表符分隔的字符串到ListBox中,实现自定义列宽布局。
Use the LB_SETTABSTOPS message and then send the ListBox strings with tab
stops (\t) in them, like this...

    #include "windows.h"
    #include "windowsx.h"

    HWND hList = // get a ListBox handle somehow
    int columns[] = { 100, 200 };

    ListBox_SetTabStops(hList, 2, &columns);

    ListBox_AddString(hList, "Col 1\tCol 2\tCol 3");
    ListBox_AddString(hList, "Foo\tBar\tBaz");
    ListBox_AddString(hList, "Red\tGreen\tBlue");

This inserts two tab stops into the ListBox at 100 and 200 pixels,
respectively.  So, when the first string added is displayed, for example,
"Col 1" will appear (horizontally) at pixel 0, "Col 2" will appear at pixel
100 and "Col 3" will appear at pixel 200.

Note that, if your ListBox items become too wide in this kind of situation,
create your ListBox with the standard WS_HSCROLL style and then send it a
LB_SETHORIZONTALEXTENT message to allow the user to scroll the ListBox
horizontally.  For example, if the ListBox manipulated by the sample code
above was actually only 200 pixels wide (and assuming each row needed 300),
you might also do this...

   ListBox_SetHorizontalExtent(hList, 300);

...to allow the user to scroll the ListBox left and right.

You may be tempted to use the LBS_MULTICOLUMN ListBox style.  However, this
is probably not appropriate for what you are doing.  LBS_MULTICOLUMN makes
the ListBox automatically "snake" the items from one column to the next
(ordering your items like columns in a newspaper).  This is a seldom-used
style of ListBox.  Also, all columns must have the same width (as set by the
LB_SETCOLUMNWIDTH message).



https://groups.google.com/forum/#!topic/borland.public.cpp.winapi/F1JdyiicTz4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值