The SetScrollPos function sets the position of the scroll box (thumb) in the specified scroll bar and, if requested, redraws the scroll bar to reflect the new position of the scroll box.
The SetScrollPos function is provided for backward compatibility. New applications should use the SetScrollInfo function.
int SetScrollPos(
HWND hWnd, // handle to window with scroll bar
int nBar, // scroll bar flag
int nPos, // new position of scroll box
BOOL bRedraw // redraw flag
);
Value | Meaning |
---|---|
SB_CTL | Sets the position of the scroll box in a scroll bar control. The hWnd parameter must be the handle to the scroll bar control. |
SB_HORZ | Sets the position of the scroll box in a window's standard horizontal scroll bar. |
SB_VERT | Sets the position of the scroll box in a window's standard vertical scroll bar. |
If the function succeeds, the return value is the previous position of the scroll box.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the scroll bar is redrawn by a subsequent call to another function, setting the bRedraw parameter to FALSE is useful.
Because the messages that indicate scroll bar position, WM_HSCROLL and WM_VSCROLL, are limited to 16 bits of position data, applications that rely solely on those messages for position data have a practical maximum value of 65,535 for the SetScrollPos function's nPos parameter.
However, because the SetScrollInfo, SetScrollPos, SetScrollRange, GetScrollInfo, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollInfo for a description of the technique.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 2.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
Scroll Bars Overview, Scroll Bar Functions, GetScrollInfo, GetScrollPos, GetScrollRange, SetScrollInfo, SetScrollRange