Set horizontal scroll bar in ListBox

Source: Internet
Author: User

Associate the control variable m_listbox with ListBox

For (INT I = 0; I <= 20; ++ I)

{

M_list.addstring (L "123456789123456789123456789123456789123456789 ");

}

When the width of the string added to the ListBox control is too long, some newly added strings cannot be displayed. In this case, you need to add a horizontal scroll bar.

First, select the horizontal scroll of ListBox.
Add the sethscroll member function to the ctestdlg class in the dialog box.

 

Void ctestdlg: sethscroll ()

{

CDC * Dc = getdc ();

Size S;

Int index;

Cstring STR;

Long temp;

For (Index = 0; index <m_list.getcount (); index ++)

{

M_list.gettext (index, STR );

S = Dc-> gettextextent (STR, str. getlength () + 1); // obtains the pixel size of a string.

// If the width of the new string is greater than the width of the previous horizontal scroll bar, reset the scroll bar width.

// ID of the resource whose idc_listbox is m_list

Temp = (long) senddlgitemmessage (idc_list1, lb_gethorizontalextent, 0, 0); // temp gets the width of the scroll bar

If (S. CX> temp)

{

Senddlgitemmessage (idc_list1, lb_sethorizontalextent, (wparam) S. CX,

0 );

}

}

Releasedc (DC );

}

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.