Scroll-Bar Input

Windows sends a scroll-bar input message, either WM_HSCROLL or WM_VSCROLL, to a window function when the user clicks with the cursor 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 get scroll-bar input, add scroll bars to the window. You can do this by specifying the WS_HSCROLL and WS_VSCROLL styles when you create the window. These 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, /* parent handle */

NULL, /* menu or child ID */

hInstance, /* instance */

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 function when the user moves the thumb of 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 or LEFT ARROW
SB_LINEDOWN User clicks the DOWN or RIGHT ARROW
SB_PAGEUP User clicks between the scroll box and the UP or LEFT ARROW
SB_PAGEDOWN User clicks between the scroll box and the DOWN or RIGHT ARROW
SB_THUMBPOSITION User releases the mouse button when the cursor is in the scroll box, typically after dragging the box
SB_THUMBTRACK User drags the scroll box with the mouse