SCROLL BARS

Scroll bars are one of the best features of a graphics and mouse interface. They are easy to use and provide good visual feedback. You can use scroll bars whenever you need to display anything—text, graphics, a spreadsheet, database records, pictures—that requires more space than the available client area of the window.

Scroll bars are positioned either vertically (for up and down movement) or horizontally (for left and right movement). You can click with the mouse on the arrows at each end of a scroll bar or on the area between the arrows. A ”scroll box,“ or ”thumb,“ travels the length of the scroll bar to indicate the approximate location of the material shown on the display in relation to the entire document. You can also drag the thumb with the mouse to move to a particular location. Figure 2-7 shows the recommended use of a vertical scroll bar for text.

Programmers sometimes have problems with scrolling terminology because their perspective is different from the user's: A user who scrolls down wants to bring a lower part of the document into view. However, the program actually moves the document up in relation to the display window. The Windows documentation and the WINDOWS.H identifiers are based on the user's perspective: Scrolling up means moving toward the beginning of the document; scrolling down means moving toward the end.

It is very easy to include a horizontal or vertical scroll bar in your application window. All you need to do is include the identifier WS_VSCROLL (vertical scroll) or WS_HSCROLL (horizontal scroll) or both to the window style in the CreateWindow statement. These scroll bars are always placed against the right side or bottom of the window and extend for the full length or width of the client area. The client area does not include the space occupied by the scroll bar. The width of a vertical window scroll bar and the height of a horizontal window scroll bar are constant for a particular display driver. If you need these values, you can obtain them (as you may have observed) from the GetSystemMetrics call.

Windows takes care of all mouse logic for the scroll bars. However, window scroll bars do not have an automatic keyboard interface. If you want the cursor keys to duplicate some of the window scroll bars' functions, you must explicitly provide logic for that (as we'll do in the next chapter).