Win32 standard controls, the list control (ListBox) does not provide a horizontal scroll bar as a list view (ListView), so if the length of the list item exceeds the width of the list, the excess is not displayed. In this article I'll take a simple example of how to use the SDK to solve this problem, in this case, I'll add 100 lines of text in the following format for a list control:
This is a very very very very very long sentence-line 1
This is a very very very very very long Sentence-line 2
......
The code that adds text to this paragraph is:
case WM_INITDIALOG:
{
int i;
TCHAR str[100];
for(i = 0; i < 100; i++)
{
wsprintf(str, "This is a very very very very very long sentence - line %d", i + 1);
SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)str);
}
}
break;
Of course, before adding a horizontal scroll bar, this is the effect of the following image:
Now I'm going to add a horizontal scrollbar for this list control, you first need to set the horizontal scroll bar for the list control in the design of the resource, and then you can add a horizontal scrollbar to it by sending a lb_sethorizontalextent message to the list control. In the additional parameters of this message, the wparam parameter is the horizontal scroll bar length in pixels, lparam not used. Then, you can set a sufficient length for this scroll bar (assuming 500), with the following code:
case WM_INITDIALOG:
{
HDC hdc;
int i;
TCHAR str[100];
for(i = 0; i < 100; i++)
{
wsprintf(str, "This is a very very very very very long sentence - line %d", i + 1);
SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)str);
}
SendDlgItemMessage(hDlg, IDC_LIST, LB_SETHORIZONTALEXTENT, 500, 0); // 设置长度为500像素的水平滚动条
}
break;
After the execution of this code, the effect is as follows: