To add a horizontal scroll bar to a list control

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.