Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls



  1. Save All


18.4.6..Scroll Bar Events.................................................................................


As described already, to use a scroll bar, the user clicks either one of its buttons, a thumb
or the scrolling region. When the user clicks, the scroll bar sends a message to its parent
or host, which can be a view, a dialog box, or a form. If the scroll bar is horizontal, the
message sent is WM_HSCROLL, which fires an OnHScroll() event. The CWnd class,
as the parent of all MFC Windows controls and views, carries this event and makes it
available to the child classes (and controls) that can perform the scrolling. The syntax of
the OnHScroll() event is:

afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

The nSBCode argument is the type of scrolling that is being performed. Its possible
values are:

Value Description Role
SB_THUMBTRACK The thumb is being dragged to a
specific position
SB_LEFT The thumb has been positioned to the
minimum value of the scroll bar, to
the extreme left.

Used to position the thumb to the
lowest value of the range

SB_LINELEFT The thumb is scrolling to the left one,
character or column at a time

Used to decrease the position of the
thumb, usually by subtracting 1 to the
current value, unless the thumb is
already positioned there
SB_PAGELEFT The thumb is scrolling to the left, one
page at a time

Refers to the page size of the
SCROLLINFO value to decrease the
current position by one page
SB_PAGERIGHT The thumb is scrolling to the right,
one page at a time

Refers to the page size of the
SCROLLINFO value to increase the
current position by one page
SB_LINERIGHT The thumb is scrolling to the right
one, character or column at a time

Used to increase the position of the
thumb, usually by adding 1, unless
the thumb is already positioned there
SB_RIGHT The thumb has been positioned to the
maximum value of the scroll bar, to
the extreme right

Used to position the thumb to the
highest value of the range, unless the
thumb is already positioned there
SB_THUMBPOSITION Absolute postion
SB_ENDSCROLL End Scroll Used to determine the end of the
scrolling

The nPos argument is used in connection with the SB_THUMBTRACK and the
SB_THUMBPOSITION values of the nSBCode argument. The value of nPos specifies
how much scrolling should be done.

The pScrollBar argument can be used to identify the particular scroll bar control needs to
be dealt with on this OnHScroll() event.

If your scroll bar control is vertical, when the user clicks it, it sends a WM_VSCROLL
message which fires the OnVScroll() event. Its syntax is:

afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
Free download pdf