如题,使滚动后,恰好可看全某一条信息。

解决方案 »

  1.   

    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; 
      

  2.   

    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;
    }

    ::SendMessage(hList,LB_SETHORIZONTALEXTENT,textLen+20,0);上面是我的写法,可是不对。我估计是循环里的那个发送消息的操作不对,应该发送哪个消息来得到长度(好像应该是像素的),可我没找到那个消息。
      

  3.   

    可以的,我以前试过的
    wParam
    Specifies the number of pixels by which the list box can be scrolled. 
    Microsoft&reg; Windows&reg; 95/Windows 98/Windows Millennium Edition (Windows Me) : The wParam parameter is limited to 16-bit values.用300先试试
    ::SendMessage(hList,LB_SETHORIZONTALEXTENT,300,0);
      

  4.   

    设的很大当然没问题,也就是说::SendMessage(hList,LB_SETHORIZONTALEXTENT,300,0);中的300,设的足够大,是可以滚动,但我要的是其宽度正好是最长的文本项(而不是无限制的长度),我上面的代码就是这一点没有实现好,应该怎么得到每一条文本项的长度,经过比较后,得到最大找长度?我上面的代码中textLen=::SendMessage(hList,LB_GETHORIZONTALEXTENT
    ,(WPARAM)i,0);这句,好像不能很好的得到其每一条记录的文本长。因为用maxTextlen设置LB_SETHORIZONTALENXTENT,并不能实现滚动》
      

  5.   

    “textLen=::SendMessage(hList,LB_GETHORIZONTALEXTENT
    ,(WPARAM)i,0);这句,好像不能很好的得到其每一条记录的文本长”这个不是文本的长阿
      

  6.   

    要发送 LB_GETTEXTLEN
      textLen=::SendMessage(hList,LB_GETTEXTLEN,(WPARAM)i,0)可能就可以了
      

  7.   

    毛毛的做法也不对。::SendMessage(hList,LB_SETHORIZONTALEXTENT,300,0);这个消息设置的长度好像是以象素为单位的。而LB_GETTEXTLEN是以字符为单位长度的。谁能帮我呀
      

  8.   

    这个函数可以获得文本的像素长度:GetTextExtentPoint32。
      

  9.   

    最简单的方法:int textLen=::SendMessage(hList,LB_GETTEXTLEN,(WPARAM)i,0);SendMessage(hList,LB_SETHORIZONTALEXTENT,textLen*8,0);注意要选WS_HSCROLL
      

  10.   

    上面的和字体有关呀,
    BOOL GetTextMetrics(
        HDC hdc, // handle of device context 
        LPTEXTMETRIC lptm  // address of text metrics structure 
       );
    要hdc的。