User Tools

Site Tools


scrollable_20list_20boxes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

scrollable_20list_20boxes [2018/03/31 13:19]
127.0.0.1 external edit
scrollable_20list_20boxes [2018/04/15 19:07] (current)
tbest3112 Added syntax highlighting
Line 7: Line 7:
   - If the longest item will not fit across the width of the list box, it is possible to arrange for a horizontal scroll bar to be added. However, this requires extra code (see below).   - If the longest item will not fit across the width of the list box, it is possible to arrange for a horizontal scroll bar to be added. However, this requires extra code (see below).
 \\  Items 1 and 2 are covered in the main [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​listbox|Help documentation]]. Although the use of the **WS_HSCROLL** and **LBS_MULTICOLUMN** style bits is described only in the section covering list boxes in a dialogue box, it is equally applicable to a [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnlistbox|listbox created on the main output window]].\\ \\  Item 3 is considerably more complicated to achieve, partly for the reasons outlined in this [[http://​support.microsoft.com/​kb/​66370|Microsoft article]]. To make it easier, the code listed below provides two procedures: **PROC_addstring** and **PROC_delstring**;​ if these are called instead of sending the LB_ADDSTRING and LB_DELETESTRING messages to the list box, the horizontal scroll bar will be controlled automatically.\\ \\  In order to enable a horizontal scroll bar, it is necessary to set the **WS_HSCROLL** style bit (&​100000). When creating the list box in a dialogue box this value should be included in the final parameter of **PROC_listbox**,​ for example:​\\ ​ \\  Items 1 and 2 are covered in the main [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​listbox|Help documentation]]. Although the use of the **WS_HSCROLL** and **LBS_MULTICOLUMN** style bits is described only in the section covering list boxes in a dialogue box, it is equally applicable to a [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnlistbox|listbox created on the main output window]].\\ \\  Item 3 is considerably more complicated to achieve, partly for the reasons outlined in this [[http://​support.microsoft.com/​kb/​66370|Microsoft article]]. To make it easier, the code listed below provides two procedures: **PROC_addstring** and **PROC_delstring**;​ if these are called instead of sending the LB_ADDSTRING and LB_DELETESTRING messages to the list box, the horizontal scroll bar will be controlled automatically.\\ \\  In order to enable a horizontal scroll bar, it is necessary to set the **WS_HSCROLL** style bit (&​100000). When creating the list box in a dialogue box this value should be included in the final parameter of **PROC_listbox**,​ for example:​\\ ​
 +<code bb4w>
         WS_HSCROLL = &100000         WS_HSCROLL = &100000
         PROC_listbox(dlg%,​ "",​ id%, x%, y%, cx%, cy%, WS_HSCROLL)         PROC_listbox(dlg%,​ "",​ id%, x%, y%, cx%, cy%, WS_HSCROLL)
 +</​code>​
 Similarly, when creating the list box on the output window include the value in the final parameter of **FN_listbox**,​ as follows:​\\ ​ Similarly, when creating the list box on the output window include the value in the final parameter of **FN_listbox**,​ as follows:​\\ ​
 +<code bb4w>
         WS_HSCROLL = &100000         WS_HSCROLL = &100000
         hlb% = FN_listbox("",​ x%, y%, cx%, cy%, id%, WS_HSCROLL)         hlb% = FN_listbox("",​ x%, y%, cx%, cy%, id%, WS_HSCROLL)
 +</​code>​
 The **WS_HSCROLL** style may be combined with any others required, but the code listed here is //__not__// compatible with the **LBS_USETABSTOPS** or **LBS_MULTICOLUMN** styles.\\ \\  Once created (and, in the case of a dialogue box, displayed) the listbox may be populated with string items. Instead of sending the usual LB_ADDSTRING message, call the **PROC_addstring** routine, which enables correct behaviour of the horizontal scroll bar. In the case of a dialogue box it is first necessary to discover the handle of the list box as follows:​\\ ​ The **WS_HSCROLL** style may be combined with any others required, but the code listed here is //__not__// compatible with the **LBS_USETABSTOPS** or **LBS_MULTICOLUMN** styles.\\ \\  Once created (and, in the case of a dialogue box, displayed) the listbox may be populated with string items. Instead of sending the usual LB_ADDSTRING message, call the **PROC_addstring** routine, which enables correct behaviour of the horizontal scroll bar. In the case of a dialogue box it is first necessary to discover the handle of the list box as follows:​\\ ​
 +<code bb4w>
         SYS "​GetDlgItem",​ !dlg%, id% TO hlb%         SYS "​GetDlgItem",​ !dlg%, id% TO hlb%
 +</​code>​
 Where **dlg%** is the value returned from **FN_newdialog** and **id%** is the ID number of the list box. In the case of a list box on the main output window, the handle is returned from **FN_listbox** as shown above.\\ \\  In either case, to populate the listbox use code similar to the following:​\\ ​ Where **dlg%** is the value returned from **FN_newdialog** and **id%** is the ID number of the list box. In the case of a list box on the main output window, the handle is returned from **FN_listbox** as shown above.\\ \\  In either case, to populate the listbox use code similar to the following:​\\ ​
 +<code bb4w>
         PROC_addstring(hlb%,​ text1$)         PROC_addstring(hlb%,​ text1$)
         PROC_addstring(hlb%,​ text2$)         PROC_addstring(hlb%,​ text2$)
         REM etc.         REM etc.
 +</​code>​
 You can, of course, add the items within a loop if more convenient.\\ \\  To delete an item from a list box, call the **PROC_delstring** routine instead of sending the LB_DELETESTRING message:​\\ ​ You can, of course, add the items within a loop if more convenient.\\ \\  To delete an item from a list box, call the **PROC_delstring** routine instead of sending the LB_DELETESTRING message:​\\ ​
 +<code bb4w>
         PROC_delstring(hlb%,​ index%)         PROC_delstring(hlb%,​ index%)
 +</​code>​
 where **index%** is the index number (starting at zero) of the item you wish to delete. If that item was longer than the others, the horizontal scroll bar will be adjusted (or removed) accordingly. Note that, by default, the items in a list box created using **PROC_listbox** are sorted into alphabetical order; therefore the index numbers of the items typically won't correspond to the order in which they were added. If necessary use the **LB_FINDSTRING** or **LB_FINDSTRINGEXACT** message to discover a string'​s index.\\ \\  To empty the listbox of all its contents, call the **PROC_resetlb** routine below.\\ \\  Finally, here are the routines which control the horizontal scroll bar:​\\ ​ where **index%** is the index number (starting at zero) of the item you wish to delete. If that item was longer than the others, the horizontal scroll bar will be adjusted (or removed) accordingly. Note that, by default, the items in a list box created using **PROC_listbox** are sorted into alphabetical order; therefore the index numbers of the items typically won't correspond to the order in which they were added. If necessary use the **LB_FINDSTRING** or **LB_FINDSTRINGEXACT** message to discover a string'​s index.\\ \\  To empty the listbox of all its contents, call the **PROC_resetlb** routine below.\\ \\  Finally, here are the routines which control the horizontal scroll bar:​\\ ​
 +<code bb4w>
         DEF PROC_addstring(hlb%,​ text$)         DEF PROC_addstring(hlb%,​ text$)
         LOCAL E%, I%, max%, nitems%         LOCAL E%, I%, max%, nitems%
Line 84: Line 95:
         SYS "​ReleaseDC",​ hwnd%, hdc%         SYS "​ReleaseDC",​ hwnd%, hdc%
         = size.x%         = size.x%
 +</​code>​
 Note that, for convenience,​ this code uses the 'user data' associated with each list box item to contain the length of the item in pixels. Therefore the 'user data' facility is not available for other purposes in your program. Note that, for convenience,​ this code uses the 'user data' associated with each list box item to contain the length of the item in pixels. Therefore the 'user data' facility is not available for other purposes in your program.
scrollable_20list_20boxes.txt ยท Last modified: 2018/04/15 19:07 by tbest3112