如题所示:我用了SendDlgItemMessage(IDC_LIST,LB_SETHORIZONTALEXTENT,200,0);但是不起作用?
谢谢。

解决方案 »

  1.   

    This message is sent by an application 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. 
    看看你的list的控件的宽度是不是大于200?
      

  2.   

    我即使把SendDlgItemMessage()函数中的200改成了10(我的控件长度肯定大于10了),但还是没有反应的,是不是缺了什么?
      

  3.   

    MSDN: To respond to the LB_SETHORIZONTALEXTENT message, the list box must have been defined with the WS_HSCROLL style看看LIST控件的属性里有没有设置 WS_HSCROLL 属性
      

  4.   

    我确定我设过了WS_HSCROLL 属性,但还是不起作用。为什么?
      

  5.   

    CListBox *pListBox;
    int nLeng = 200;
    pListBox = (CListBox*)GetDlgItem(IDC_List1)
    pListBox->SetHorizontalExtent(nLeng);
      

  6.   

    ListBox 用SetHorizontalExtent函数
      

  7.   

    这是我自己用过的一段代码
    void CNetClientDlg::SetHScroll()
    {
    CListBox *pLstBox = static_cast<CListBox *>(GetDlgItem(IDC_LIST_RESULT)); CDC* dc = GetDC();
    SIZE s;
    int index;
    CString str;
    long temp;
    for(index= 0; index< pLstBox->GetCount(); index++)
    {
    pLstBox->GetText(index,str);
    s = dc->GetTextExtent(str,str.GetLength()+1);   // 获取字符串的像素大小
    // 如果新的字符串宽度大于先前的水平滚动条宽度,则重新设置滚动条宽度
    temp = (long)SendDlgItemMessage(IDC_LIST_RESULT, LB_GETHORIZONTALEXTENT, 0, 0); //temp得到滚动条的宽度
    if (s.cx > temp)  
    {
    SendDlgItemMessage(IDC_LIST_RESULT, LB_SETHORIZONTALEXTENT, (WPARAM)s.cx, 0);
    }
    }
    ReleaseDC(dc);
    }
      

  8.   

    你可能需要用到这个API:ListView_SetWorkAreas(),根据MSDN的文档,如果设置的工作大于客户区宽度,则水平滚动条自动出现。