User Tools

Site Tools


Scrolling a list box

by Richard Russell, March 2007

You can scroll the contents of a list box, under the control of your own program, by sending it a WM_VSCROLL message. The simple program below illustrates the use of that technique:

        INSTALL @lib$+"WINLIB5"
        WS_VSCROLL = &200000
        WS_BORDER = &800000
        LB_ADDSTRING = 384
        WM_VSCROLL = 277
        SB_BOTTOM = 7
        hlist%=FN_listbox("", 20, 20, 200, 200, 1, WS_VSCROLL + WS_BORDER)
          WAIT 50
          item% += 1
          SYS "SendMessage", hlist%, LB_ADDSTRING, 0, "Line "+STR$item%
          SYS "SendMessage", hlist%, WM_VSCROLL, SB_BOTTOM, 0

Here the SB_BOTTOM scroll command is sent, which causes the list box to scroll so the last item is in view. The full set of commands is as follows:

        SB_LINEUP = 0   : REM Scrolls one line up
        SB_LINEDOWN = 1 : REM scrolls one line down
        SB_PAGEUP = 2   : REM Scrolls one page up
        SB_PAGEDOWN = 3 : REM Scrolls one page down
        SB_TOP = 6      : REM Scrolls to the top
        SB_BOTTOM = 7   : REM scrolls to the bottom

The code shown is appropriate for scrolling a list box on your main window. You can similarly scroll a listbox within a dialogue box by using SendDlgItemMessage as below:

        SYS "SendDlgItemMessage", !dlg%, idlist%, WM_VSCROLL, SB_BOTTOM, 0
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
scrolling_20a_20list_20box.txt · Last modified: 2018/04/15 20:02 by tbest3112