SetScrollRange function (winuser.h)

The SetScrollRange function sets the minimum and maximum scroll box positions for the specified scroll bar.

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

Syntax

BOOL SetScrollRange(
  [in] HWND hWnd,
  [in] int  nBar,
  [in] int  nMinPos,
  [in] int  nMaxPos,
  [in] BOOL bRedraw
);

Parameters

[in] hWnd

Type: HWND

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

[in] nBar

Type: int

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

Value Meaning
SB_CTL
Sets the range of a scroll bar control. The hwnd parameter must be the handle to the scroll bar control.
SB_HORZ
Sets the range of a window's standard horizontal scroll bar.
SB_VERT
Sets the range of a window's standard vertical scroll bar.

[in] nMinPos

Type: int

Specifies the minimum scrolling position.

[in] nMaxPos

Type: int

Specifies the maximum scrolling position.

[in] bRedraw

Type: BOOL

Specifies whether the scroll bar should be redrawn to reflect the change. If this parameter is TRUE, the scroll bar is redrawn. If it is FALSE, the scroll bar is not redrawn.

Return value

Type: BOOL

If the function succeeds, the return value is nonzero.

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

Remarks

You can use SetScrollRange to hide the scroll bar by setting nMinPos and nMaxPos to the same value. An application should not call the SetScrollRange function to hide a scroll bar while processing a scroll bar message. New applications should use the ShowScrollBar function to hide the scroll bar.

If the call to SetScrollRange immediately follows a call to the SetScrollPos function, the bRedraw parameter in SetScrollPos must be zero to prevent the scroll bar from being drawn twice.

The default range for a standard scroll bar is 0 through 100. The default range for a scroll bar control is empty (both the nMinPos and nMaxPos parameter values are zero). The difference between the values specified by the nMinPos and nMaxPos parameters must not be greater than the value of MAXLONG.

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 SetScrollRange function's nMaxPos 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_SETRANGE message to the window to set scroll bar information. This allows SetScrollRange to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_SETRANGE message, the SetScrollRange function fails.

Examples

For an example, see Using the Owner-Display Clipboard Format.

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-misc-l1-2-0 (introduced in Windows 8.1)

See also

GetScrollInfo

GetScrollPos

GetScrollRange

Reference

SetScrollInfo

SetScrollPos

ShowScrollBar