Keyboard accessibility for scrollbars

Date:August 5, 2003 / year-entry #13
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20030805-00/?p=42983
Comments:    3
Summary:Note that so far, the scrollbar is accessible only with the mouse. Our next step is to add keyboard access to the scrollbar. Fortunately, this is not all that difficult. We merely map some keystrokes to equivalent scrollbar actions. void OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags) { if (fDown) { switch...

Note that so far, the scrollbar is accessible only with the mouse. Our next step is to add keyboard access to the scrollbar. Fortunately, this is not all that difficult. We merely map some keystrokes to equivalent scrollbar actions.

void OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
{
    if (fDown) {
        switch (vk) {
        case VK_UP:         ScrollDelta(hwnd, -cRepeat); break;
        case VK_DOWN:       ScrollDelta(hwnd, +cRepeat); break;
        case VK_PRIOR:      ScrollDelta(hwnd, -cRepeat*g_cyPage); break;
        case VK_NEXT:       ScrollDelta(hwnd, +cRepeat*g_cyPage); break;
        case VK_HOME:       ScrollTo(hwnd, 0); break;
        case VK_END:        ScrollTo(hwnd, MAXLONG); break;
        }
    }
}

    /* Add to WndProc */
    HANDLE_MSG(hwnd, WM_KEYDOWN, OnKey);

Note that this doesn't make our sample program fully accessible; this just makes the scrollbars accessible. Full accessibility will be covered in a (much) later blog entry. Right now, I'm just focusing on scrollbars.


Comments (3)
  1. Murph says:

    Did you declare g_cyPage? (Maybe I missed it.)

  2. Mike Jackson says:

    Raymond,

    Ive just started going through this Scrollbar tutorial (excellent by the way!), but I can not see where you declare (or set) g_cyPage that is used in this and subsequent lessons.

  3. Raymond Chen says:

    Oops, g_cyPage should be g_cLinesPerPage.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index