The position of the scroll box is represented as an integer. The position is relative to the left or upper end of the scroll bar, depending on whether the scroll bar is horizontal or vertical. The position must be within the scrolling range, which is defined by minimum and maximum values. The positions are distributed equally along the scroll bar. For example, if the range is 0 through 100, there are 100 positions along the scroll bar, each equally spaced so that position 50 is in the middle of the scroll bar. The initial range depends on the scroll bar. Standard scroll bars have an initial range of 0 through 100; scroll bar controls have an empty range (both minimum and maximum values are zero) if no explicit range is given when the control is created. You can change the range at any time by using the SetScrollRange function to set new minimum and maximum values. The GetScrollRange function retrieves the current minimum and maximum values.
You can adjust a scroll bar's range to convenient integers by using the SetScrollRange function. This makes it easy to translate the scroll-box position into a value that corresponds to the data being scrolled. For example, if your application needs to display 260 lines of text in a window that can show only 16 lines at a time, you could set the vertical scroll bar range to 1 through 244. If the scroll box were at position 1, the first line would be at the top of the window. If the scroll box were at position 244, the last line (line 260) would be at the bottom of the window. If SetScrollPos specifies a position value that is less than the minimum or more than the maximum, the minimum or maximum value is used instead.
To establish a useful relationship between the scroll bar range and the data, an application must adjust the range whenever the data or the size of the window changes. This means the application should adjust the range as part of processing WM_SIZE messages.
As the user moves the scroll box in a scroll bar, the scroll bar reports the scroll-box position as an integer in the scrolling range. If the scroll-box position is the minimum value, the scroll-box is at the top of a vertical scroll bar or at the left end of a horizontal scroll bar. If the scroll-box position is the maximum value, the scroll-box is at the bottom or right end of the vertical or horizontal scroll bar, respectively.
An application must move the scroll-box in a scroll bar. Although the user makes a request for scrolling in a scroll bar, the scroll bar does not update the scroll-box position. Instead, it passes the request to the parent window, which must scroll the data and update the scroll-box position by using the SetScrollPos function. Because the application controls the scroll-box movement, it can move the scroll-box in increments that work best for the data being scrolled.