Você está na página 1de 3

Setting Scroll Bar Properties

Getting and setting scroll bar value, max, min and large-
change properties is achieved via the GetScrollInfo and
SetScrollInfo properties, which work on the
SCROLLINFO structure:
' Scroll bar:
Private Type SCROLLINFO
cbSize As Long ' Size of structure
fMask As Long ' Which value(s) you are
changing
nMin As Long ' Minimum value of the
scroll bar
nMax As Long ' Maximum value of the
scroll bar
nPage As Long ' Large-change amount
nPos As Long ' Current value
nTrackPos As Long ' Current scroll position
End Type

' 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 - SmallChange
Private Const SB_LINEDOWN = 1
' - Set scroll value to value + SmallChange
Private Const SB_LINELEFT = 0
' - Set scroll value to value + SmallChange
Private Const SB_LINERIGHT = 1
' - Set scroll value to value - SmallChange
Private Const SB_LINEUP = 0
' - Set scroll value to value + LargeChange
Private Const SB_PAGEDOWN = 3
' - Set scroll value to value - LargeChange
Private Const SB_PAGELEFT = 2
' - Set scroll value to value + LargeChange
Private Const SB_PAGERIGHT = 3
' - Set scroll value to value - LargeChange
Private Const SB_PAGEUP = 2
' - Set scroll value to max
Private Const SB_RIGHT = 7
' - Not required?
Private Const SB_THUMBPOSITION = 4
' - Set scroll value to track position
Private Const SB_THUMBTRACK = 5
' - Set scroll value to min
Private 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.

Você também pode gostar