Article ID: 152252 - Last Review: November 21, 2006 - Revision: 2.1 HOWTO: How To Get 32-bit Scroll Position During Scroll MessagesThis article was previously published under Q152252 On This PageSUMMARY
The current scroll bar position accompanying the SB_THUMBTRACK and
SB_THUMBPOSITION type of scroll messages is only 16-bits wide. Functions
such as GetScrollPos, SetScrollPos, GetScrollRange, and SetScrollRange can
handle 32-bit value scroll-box positions. This article discusses how the
GetScrollInfo call can be used to retrieve 32-bit scroll position during
scroll messages.
MORE INFORMATION
One of the arguments to the MFC scroll message handlers, OnHScroll and
OnVScroll, is the scroll box position. This argument is meaningful only in
the case of scroll messages with scroll bar code SB_THUMBPOSITION and
SB_THUMBTRACK. This value, even though of type UINT, is really of type
short int. In other words, the scroll thumb position is only 16-bits wide.
This behavior occurs because Windows sends the thumb position in the High
Word of WPARAM accompanying the scroll message. To obtain 32-bit scroll positions, the OnxScroll handler should make a call to GetScrollInfo with the mask set to SIF_TRACKPOS. The immediate position of the scroll thumb is returned in the nTrackPos member of the SCROLLINFO structure passed in to GetScrollInfo. This functionality was embedded in MFC 4.0 classes and was handled by the function CWnd::OnWndMsg. However, this gave rise to other problems. As a consequence, the functionality was withdrawn in MFC 4.1 and it was left to the user to extract 32-bit values for the scroll box. For more information on this subject, please see the following article in the Microsoft Knowledge Base: 147684
(http://support.microsoft.com/kb/147684/EN-US/
)
BUG: Sending WM_xSCROLL Messages Causes Invalid ASSERT
This method of extracting 32-bit scroll box positions works only in those
scroll messages that are sent to a window when the user grabs the thumb and
drags it. It is not possible to obtain 32-bit scroll box position in cases
of programmatically sent SB_THUMBTRACK and SB_THUMBPOSITION scroll
messages. First, the 32-bit information cannot be packed into the WPARAM of
the messages because only the High Word contains the scroll position.
Second, the nTrackPos member of the SCROLLINFO structure maintained for
scroll bars cannot be set programmatically. Any calls to SetScrollInfo to
set the immediate scroll positions are ignored by the operating system.
Sample CodeAPPLIES TO
| Article Translations
|

Back to the top
