45.2.4 Creating a Keyboard Interface for a Standard Scroll Bar

A scroll bar control provides a built-in keyboard interface, but a standard scroll bar does not. To implement a keyboard interface for a standard scroll bar, your window procedure must process the WM_KEYDOWN message, examining the virtual-key code specified by the wParam parameter. If the virtual-key code corresponds to a direction key, your window procedure should send itself a WM_HSCROLL or WM_VSCROLL message with the wParam parameter set to the appropriate scroll bar notification code. For example, when the user presses the UP ARROW key, your window procedure receives a WM_KEYDOWN message with wParam equal to VK_UP. In response, your window procedure should send itself a WM_VSCROLL message with the low-order word of wParam set to the SB_LINEUP notification code.

The following example shows how to include a keyboard interface for a standard scroll bar:

WORD wScrollNotify = -1;

.

.

.

case WM_KEYDOWN:

switch (wParam) {

case VK_UP:

wScrollNotify = SB_LINEUP;

break;

case VK_PRIOR:

wScrollNotify = SB_PAGEUP;

break;

case VK_NEXT:

wScrollNotify = SB_PAGEDOWN;

break;

case VK_DOWN:

wScrollNotify = SB_LINEDOWN;

break;

case VK_HOME:

wScrollNotify = SB_TOP;

break;

case VK_END:

wScrollNotify = SB_BOTTOM;

break;

}

if (wScrollNotify != -1)

SendMessage(hwnd, WM_VSCROLL,

MAKELONG(wScrollNotify, 0), 0L);

break;

.

.

.