{"id":90531,"date":"2003-08-05T00:42:00","date_gmt":"2003-08-05T00:42:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20030805-00\/?p=90531\/"},"modified":"2020-04-02T19:22:20","modified_gmt":"2020-04-03T02:22:20","slug":"answer-to-previous-exercise-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030805-00\/?p=90531","title":{"rendered":"Answer to previous exercise on proportional scrollbars"},"content":{"rendered":"<p>If you look at the WM_VSCROLL message, you&#8217;ll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won&#8217;t be able to use the scroll thumb to get to the ones at the end.<\/p>\n<p>Try it: Change the value of g_cItems to 100000 and watch what happens.<\/p>\n<p>The fix is to ignore the <code>pos<\/code> passed to the message and instead get it from the scrollbar. This helper function will prove useful.<\/p>\n<pre>UINT GetTrackPos(HWND hwnd, int fnBar)\r\n{\r\n    SCROLLINFO si;\r\n    si.cbSize = sizeof(si);\r\n    si.fMask = SIF_TRACKPOS;\r\n    if (GetScrollInfo(hwnd, fnBar, &amp;si)) {\r\n        return si.nTrackPos;\r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n<p>Change the two case statements in <code>OnVscroll<\/code> as follows:<\/p>\n<pre>    case SB_THUMBPOSITION:  ScrollTo(hwnd, GetScrollPos(hwnd, SB_VERT)); break;\r\n    case SB_THUMBTRACK:     ScrollTo(hwnd, GetTrackPos(hwnd, SB_VERT)); break;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you look at the WM_VSCROLL message, you&#8217;ll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-90531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you look at the WM_VSCROLL message, you&#8217;ll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=90531"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90531\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=90531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=90531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=90531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}