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 ); } |