Windows sends a scroll bar message, either WM_HSCROLL or WM_VSCROLL, to a window procedure each time the user clicks when the cursor is in a scroll bar. Applications use the scroll bar messages to direct scrolling within the window. Applications that display text or other data that does not all fit in the client area usually provide some form of scrolling. Scroll bars are an easy way to let the user direct scrolling actions.
To retrieve scroll bar input in your application, add scroll bars to a window. You can do this by specifying the WS_HSCROLL and WS_VSCROLL styles when you create the window. These styles direct the CreateWindow function to create horizontal and vertical scroll bars for the window. The following example creates scroll bars for the given window:
hWnd = CreateWindow("InputWClass", /* window class */
"Input Sample Application", /* window name */
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, /* x position */
CW_USEDEFAULT, /* y position */
CW_USEDEFAULT, /* width */
CW_USEDEFAULT, /* height */
NULL, /* handle of parent window */
NULL, /* handle of menu or child window */
hinst, /* instance handle */
NULL); /* additional info */
Windows displays the scroll bars when it displays the window. It automatically maintains the scroll bars and sends scroll bar messages to the window procedure when the user moves the scroll box in the scroll bar.
When Windows sends a scroll bar message, it sets the wParam parameter of the message to indicate the type of scrolling request made. For example, if the user clicks the up arrow of a vertical scroll bar, Windows sets the wParam parameter to the value SB_LINEUP. Depending on the event, Windows sets the wParam parameter to one of the following values:
Value | Event |
SB_LINEUP | User clicks the up arrow or left arrow of a scroll bar. |
SB_LINEDOWN | User clicks the down arrow or right arrow of a scroll bar. |
SB_PAGEUP | User clicks between the scroll box and the up arrow or left arrow of a scroll bar. |
SB_PAGEDOWN | User clicks between the scroll box and the down arrow or right arrow of a scroll bar. |
SB_THUMBPOSITION | User releases the mouse button when the cursor is in the scroll box (thumb)—typically, after dragging the box. |
SB_THUMBTRACK | User drags the scroll box with the mouse. |