1.8.2 Scroll Box

The scroll box is the small rectangle in a scroll bar. It shows the approximate location within the current document or file of the data currently displayed in the client area. For example, the scroll box is in the middle of the scroll bar when page three of a five-page document is in the client area.

The SetScrollPos function sets the scroll box position in a scroll bar. Because Windows does not automatically update the scroll box position when an application scrolls, SetScrollPos must be used to update the position. The GetScrollPos function retrieves the current position.

A scroll box position 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 scroll-bar 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 101 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 0) if no explicit range is given when the control is created. An application can change the range by using the SetScrollRange function to set new minimum and maximum values so that applications can change the range at any time. The GetScrollRange function retrieves the current minimum and maximum values. The minimum and maximum values can be any integers. For example, a spreadsheet program with 255 rows can set the vertical scroll range to 1 through 255.

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. SetScrollPos moves the scroll box along the scroll bar.