Featured Posts

Scroll Bar Range and Position

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 25-10-2009

0

Every scroll bar has an associated “range” and “position.” The scroll bar range is a pair of integers representing a minimum and maximum value associated with the scroll bar. The position is the location of the thumb within the range. When the thumb is at the top (or left) of the scroll bar, the position of the thumb is the minimum value of the range. At the bottom (or right) of the scroll bar, the thumb position is the maximum value of the range.

By default, the range of a scroll bar is 0 (top or left) through 100 (bottom or right), but it’s easy to change the range to something that is more convenient for the program:

SetScrollRange (hwnd, iBar, iMin, iMax, bRedraw) ;

iBar argument is either SB_VERT or SB_HORZ.

iMin and iMax are the new minimum and maximum positions of the range.

bRedraw to TRUE if you want Windows to redraw the scroll bar based on the new range. (If you will be calling other functions that affect the appearance of the scroll bar after you call SetScrollRange, you’ll probably want to set bRedraw to FALSE to avoid excessive redrawing.)

hwnd parameter to the window procedure is the handle of the window changing in size. (Remember that one window procedure could be handling messages for multiple windows that were created based on the same window class. The hwnd parameter lets the window procedure know which window is receiving the message.) The message parameter is WM_SIZE. The wParam parameter for a WM_SIZE message is the value SIZE_RESTORED, SIZE_MINIMIZED, SIZE_MAXIMIZED, SIZE_MAXSHOW, or SIZE_MAXHIDE (defined in the WINUSER.H header file as the numbers 0 through 4). That is, the wParam parameter indicates whether the window is being changed to a nonminimized or nonmaximized size, being minimized, being maximized, or being hidden.

The thumb position is always a discrete integral value. For instance, a scroll bar with a range of 0 through 4 has five thumb positions
Scroll Bar Range and Position

How to set the Thumb Position of the window

SetScrollPos (hwnd, iBar, iPos, bRedraw);

SetScrollPos to set a new thumb position within the scroll bar range.

iPos argument is the new position and must be within the range of iMin and iMax. Windows provides similar functions (GetScrollRange and GetScrollPos) to obtain the current range and position of a scroll bar.

Windows’ responsibilities for scroll bars:

  • Handle all processing of mouse messages to the scroll bar.
  • Provide a reverse-video “flash” when the user clicks the scroll bar.
  • Move the thumb as the user drags the thumb within the scroll bar.
  • Send scroll bar messages to the window procedure of the window containing the scroll bar.

Responsibilities of your program:

  • Initialize the range and position of the scroll bar.
  • Process the scroll bar messages to the window procedure.
  • Update the position of the scroll bar thumb.
  • Change the contents of the client area in response to a change in the scroll bar.
VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)