Export (0) Print
Expand All

GetScrollPos function

The GetScrollPos function retrieves the current position of the scroll box (thumb) in the specified scroll bar. The current position is a relative value that depends on the current scrolling range. For example, if the scrolling range is 0 through 100 and the scroll box is in the middle of the bar, the current position is 50.

Note   The GetScrollPos function is provided for backward compatibility. New applications should use the GetScrollInfo function.

Syntax


int GetScrollPos(
  _In_  HWND hWnd,
  _In_  int nBar
);

Parameters

hWnd [in]

Type: HWND

Handle to a scroll bar control or a window with a standard scroll bar, depending on the value of the nBar parameter.

nBar [in]

Type: int

Specifies the scroll bar to be examined. This parameter can be one of the following values.

ValueMeaning
SB_CTL

Retrieves 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

Retrieves the position of the scroll box in a window's standard horizontal scroll bar.

SB_VERT

Retrieves the position of the scroll box in a window's standard vertical scroll bar.

 

Return value

Type: int

If the function succeeds, the return value is the current position of the scroll box.

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

Remarks

The GetScrollPos function enables applications to use 32-bit scroll positions. Although the messages that indicate scroll bar position, WM_HSCROLL and WM_VSCROLL, are limited to 16 bits of position data, the functions SetScrollPos, SetScrollRange, GetScrollPos, and GetScrollRange support 32-bit scroll bar position data. Thus, an application can call GetScrollPos while processing either the WM_HSCROLL or WM_VSCROLL messages to obtain 32-bit scroll bar position data.

To get the 32-bit position of the scroll box (thumb) during a SB_THUMBTRACK request code in a WM_HSCROLL or WM_VSCROLL message, use the GetScrollInfo function.

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_GETPOS message to the window to obtain scroll bar information. This allows GetScrollPos to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_GETPOS message, the GetScrollPos function fails.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
GetScrollInfo
GetScrollRange
SetScrollInfo
SetScrollPos
SetScrollRange
WM_HSCROLL
WM_VSCROLL

 

 

Community Additions

ADD
Show:
© 2014 Microsoft