-
ListBox控件属性:Horizontal Scroll设置为true -
代码实现:根据字串长度刷新水平滚动条 //控件ID:IDC_LIST_CLIENT //控件对象:CListBox mClientList -
使用:在有mClientList.AddString()后面调用即可。
void CxxxDlg::SetHorizontalScroll()
{
CDC* pDC = GetDC();
SIZE size;
int nIndex;
CString str;
long nLen;
CFont* pFont = mClientList.GetFont();
CFont* pOldFont = pDC->SelectObject(pFont);
for (nIndex = 0; nIndex< mClientList.GetCount(); nIndex++)
{
mClientList.GetText(nIndex, str);
size = pDC->GetTextExtent(str, str.GetLength() + 1);
nLen = (long)SendDlgItemMessage(IDC_LIST_CLIENT, LB_GETHORIZONTALEXTENT, 0, 0);
if (size.cx > nLen)
{
SendDlgItemMessage(IDC_LIST_CLIENT, LB_SETHORIZONTALEXTENT, (WPARAM)size.cx, 0);
}
}
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
}
|