LB_SETHORIZONTALEXTENT An application sends an LB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden. LB_SETHORIZONTALEXTENT wParam = (WPARAM) cxExtent; // horizontal scroll width lParam = 0;
int maxTextLen=0; int n=::SendMessage(hList,LB_GETCOUNT,0,0); for(int i=0;i<n;i++) { textLen=::SendMessage(hList,LB_GETHORIZONTALEXTENT ,(WPARAM)i,0); if(textLen>maxTextLen) maxTextLen=textLen; }
可以的,我以前试过的 wParam Specifies the number of pixels by which the list box can be scrolled. Microsoft® Windows® 95/Windows 98/Windows Millennium Edition (Windows Me) : The wParam parameter is limited to 16-bit values.用300先试试 ::SendMessage(hList,LB_SETHORIZONTALEXTENT,300,0);
An application sends an LB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden. LB_SETHORIZONTALEXTENT
wParam = (WPARAM) cxExtent; // horizontal scroll width
lParam = 0;
int n=::SendMessage(hList,LB_GETCOUNT,0,0); for(int i=0;i<n;i++)
{
textLen=::SendMessage(hList,LB_GETHORIZONTALEXTENT
,(WPARAM)i,0);
if(textLen>maxTextLen)
maxTextLen=textLen;
}
::SendMessage(hList,LB_SETHORIZONTALEXTENT,textLen+20,0);上面是我的写法,可是不对。我估计是循环里的那个发送消息的操作不对,应该发送哪个消息来得到长度(好像应该是像素的),可我没找到那个消息。
wParam
Specifies the number of pixels by which the list box can be scrolled.
Microsoft® Windows® 95/Windows 98/Windows Millennium Edition (Windows Me) : The wParam parameter is limited to 16-bit values.用300先试试
::SendMessage(hList,LB_SETHORIZONTALEXTENT,300,0);
,(WPARAM)i,0);这句,好像不能很好的得到其每一条记录的文本长。因为用maxTextlen设置LB_SETHORIZONTALENXTENT,并不能实现滚动》
,(WPARAM)i,0);这句,好像不能很好的得到其每一条记录的文本长”这个不是文本的长阿
textLen=::SendMessage(hList,LB_GETTEXTLEN,(WPARAM)i,0)可能就可以了
BOOL GetTextMetrics(
HDC hdc, // handle of device context
LPTEXTMETRIC lptm // address of text metrics structure
);
要hdc的。