windows_programming_notes.nbk: Home | Index | Next Page: SetScrollRange | Previous Page: SetScrollInfo


 SetScrollPos

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.

Note The SetScrollPos function is provided for backward compatibility. New applications should use the SetScrollInfo function.

Syntax

    int SetScrollPos(  
        HWND hWnd,
        int nBar,
        int nPos,
        BOOL bRedraw
    );

Parameters

Return Value

If the function succeeds, the return value is the previous position of the scroll box. Windows XP: If the desktop is themed and the parent window is a message-only window, the function returns an incorrect value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

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.

If the nBar parameter is SB_CTL and the window specified by the hWnd parameter is not a system scroll bar control, the system sends the SBM_SETPOS message to the window to set scroll bar information. This allows SetScrollPos to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_SETPOS message, the SetScrollPos function fails.

Function Information

See Also

[Scroll Bars], GetScrollInfo, GetScrollPos, [GetScrollRange], SetScrollInfo, SetScrollRange


windows_programming_notes.nbk: Home | Index | Next Page: SetScrollRange | Previous Page: SetScrollInfo


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time