scrollbar (window) styles:
Code:
WS_VSCROLL
WS_HSCROLL
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:
Code:
SetScrollRange(hwnd, iBar, iMin, iMax, bRedraw);
you can use SetScrollPos( ) to set a new thumb position withing a scroll bar range:
Code:
SetScrollPos(hwnd, iBar, iPos, bRedraw);
General Strategy for Scrollbar Implementation
Two general methods for repainting a window after scrollbar movement. The first way, is to repaint the window only once.. after the user has completed movement of the scrollbar thumb. This method basically sucks, because the user has to guess the correct location of where they wish to scroll.
The second method (and most popular) is the repaint the window as the user is moving the scrollbar. This involves real-time processing of WM_VSCROLL and WM_HSCROLL messages. The wParam is divided into a low word and high word. The low word of wParam is a number that indicates what the mouse is doing to the scroll bar:
Code:
SB_LINEUP
SB_LINELEFT
SB_LINEDOWN
SB_LINERIGHT
SB_PAGEUP
SB_PAGELEFT
SB_PAGEDOWN
SB_PAGERIGHT
SB_THUMBPOSITION
SB_THUMBTRACK
SB_TOP
SB_LEFT
SB_BOTTOM
SB_RIGHT
SB_ENDSCROLL
Here are some additional thoughts to consider:
Window's responsibility for scrollbar maintenance
- 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 message 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.
Here is some example code that you can examine that may add some inside on scrollbar implementation. Here is the header file, and here is the .c driver program. (yes it is a .c file, but it's all winapi) Basically, the program will display all the "system metrics" of your computer.. but more importantly, it introduces scrollbar concept.