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?
看看你的list的控件的宽度是不是大于200?
int nLeng = 200;
pListBox = (CListBox*)GetDlgItem(IDC_List1)
pListBox->SetHorizontalExtent(nLeng);
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);
}