Setting Scroll Bar Properties Getting and setting scroll bar value, max, min and largechange properties is achieved via the GetScrollInfo and SetScrollInfo properties, which work on the SCROLLINFO structure: ' Scroll bar: Private Type SCROLLINFO cbSize As Long ' fMask As Long ' changing nMin As Long ' scroll bar nMax As Long ' scroll bar nPage As Long ' nPos As Long ' nTrackPos As Long ' End Type
Size of structure Which value(s) you are Minimum value of the Maximum value of the Large-change amount Current value Current scroll position
' SCROLLINFO fMask constants: Private Const SIF_RANGE = &H1 Private Const SIF_PAGE = &H2 Private Const SIF_POS = &H4 Private Const SIF_DISABLENOSCROLL = &H8 Private Const SIF_TRACKPOS = &H10 Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
Note that the actual Max value of the scroll bar is actually equal to the nMax value plus the nPage value, so when modifying the LargeChange or Max value you have to take this into account.
This allows you to set up the scroll bars. You then need to respond to the scroll bar position changing. This is done by intercepting the WM_HSCROLL and WM_VSCROLL messages sent to the window you have added scroll bars to: ' Scroll bar messages: Private Const WM_VSCROLL = &H115 Private Const WM_HSCROLL = &H114 ' Scroll bar type constants: Private Const SB_HORZ = 0 Private Const SB_VERT = 1 Private Const SB_CTL = 2 Private Const SB_BOTH = 3 ' Scroll bar notification types (returned in the first ' 16 bits of the wParam parameter of the message i.e. ' (wParam And &HFFFF&): ' - Set scroll value to max Private Const SB_BOTTOM = 7 ' - Set scroll value to max Private Const SB_ENDSCROLL = 8 ' - Time to raise Change event Private Const SB_LEFT = 6 ' - Set scroll value to value Private Const SB_LINEDOWN = 1 ' - Set scroll value to value + Private Const SB_LINELEFT = 0 ' - Set scroll value to value + Private Const SB_LINERIGHT = 1 ' - Set scroll value to value -
SmallChange SmallChange SmallChange SmallChange
Private ' - Set Private ' - Set Private ' - Set Private ' - Set Private ' - Set Private ' - Not Private ' - Set Private ' - Set Private
Const SB_LINEUP = 0 scroll value to value + LargeChange Const SB_PAGEDOWN = 3 scroll value to value - LargeChange Const SB_PAGELEFT = 2 scroll value to value + LargeChange Const SB_PAGERIGHT = 3 scroll value to value - LargeChange Const SB_PAGEUP = 2 scroll value to max Const SB_RIGHT = 7 required? Const SB_THUMBPOSITION = 4 scroll value to track position Const SB_THUMBTRACK = 5 scroll value to min Const SB_TOP = 6
Once this is done, it is a simple matter to set the appropriate value using the GetScrollInfo and SetScrollInfo API methods. These ensure you have access to the full 32bit range for the scroll bar rather than the old 16 bit (-32,768 to 32,767) values. To use Flat Scroll bars, simply use the FlatSB_ versions of the API calls instead. The cScrollBars.cls code in the downloads shows how it is done.