Answer to previous exercise

Date:August 5, 2003 / year-entry #11
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20030805-00/?p=90531
Comments:    0
Summary:If you look at the WM_VSCROLL message, you'll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won't be able to use the scroll thumb to get to the ones at the end. Try it: Change the value of g_cItems to 100000 and watch...

If you look at the WM_VSCROLL message, you'll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won't be able to use the scroll thumb to get to the ones at the end.

Try it: Change the value of g_cItems to 100000 and watch what happens.

The fix is to ignore the pos passed to the message and instead get it from the scrollbar. This helper function will prove useful.

UINT GetTrackPos(HWND hwnd, int fnBar)
{
    SCROLLINFO si;
    si.cbSize = sizeof(si);
    si.fMask = SIF_TRACKPOS;
    if (GetScrollInfo(hwnd, fnBar, &si)) {
        return si.nTrackPos;
    }
    return 0;
}

Change the two case statements in OnVscroll as follows:

    case SB_THUMBPOSITION:  ScrollTo(hwnd, GetScrollPos(hwnd, SB_VERT)); break;
    case SB_THUMBTRACK:     ScrollTo(hwnd, GetTrackPos(hwnd, SB_VERT)); break;


*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