{"id":43053,"date":"2003-07-25T16:22:00","date_gmt":"2003-07-25T16:22:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/07\/25\/scrollbars-part-2\/"},"modified":"2003-07-25T16:22:00","modified_gmt":"2003-07-25T16:22:00","slug":"scrollbars-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030725-00\/?p=43053","title":{"rendered":"Scrollbars, part 2"},"content":{"rendered":"<p>\n        Managing scrollbars is not hard in principle. The basic idea is not that difficult,\n        but there are a lot of small details that need to be ironed out. If you don&#8217;t get\n        the details just right, your program will feel odd in a strange way that you often\n        can&#8217;t pinpoint, much like a subtle background hum that makes you feel uneasy without\n        realizing it. Getting the details right is important to making your program feel crisp\n        and clean.\n    <\/p>\n<p>    <b>The base program<\/b><\/p>\n<p>\n        Let&#8217;s start with a basic program and gradually add scrollbar features to it. The basic\n        program merely displays one hundred numbered lines. Add these variables to the scratch\n        program:\n    <\/p>\n<pre>HFONT g_hfList;         \/* Font for list *\/\nint g_cyLine;           \/* Height of each line *\/\nint g_cItems = 100;     \/* Number of items *\/\n<\/pre>\n<p>\n        and add these functions to the scratch program:\n    <\/p>\n<pre>BOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n    \/* Create the font we use for the list *\/\n    LOGFONT lf;\n    SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &amp;lf, 0);\n    g_hfList = CreateFontIndirect(&amp;lf);\n    if (!g_hfList) return 0;\n    \/* Compute the height for each line *\/\n    HDC hdc = GetDC(hwnd);\n    HFONT hfPrev = SelectFont(hdc, g_hfList);\n    SelectFont(hdc, hfPrev);\n    SIZE siz;\n    GetTextExtentPoint(hdc, TEXT(\"0\"), 1, &amp;siz);\n    g_cyLine = siz.cy;\n    ReleaseDC(hwnd, hdc);\n    return 1;\n}\nvoid\nOnDestroy(HWND hwnd)\n{\n    DeleteObject(g_hfList);\n    PostQuitMessage(0);\n}\n\/* This is a separate function for now; you'll see why later *\/\nvoid\nPaintSimpleContent(HWND hwnd, PAINTSTRUCT *pps)\n{\n    HFONT hfPrev = SelectFont(pps-&gt;hdc, g_hfList);  \/* Use the right font *\/\n    for (int i = 0; i &lt; g_cItems; i++) {            \/* Print all the lines *\/\n        char szLine[256];\n        int cch = wsprintf(szLine, \"This is line %d\", i);\n        TextOut(pps-&gt;hdc, 0, i * g_cyLine, szLine, cch);\n    }\n    SelectFont(pps-&gt;hdc, hfPrev);\n}\nvoid\nPaintContent(HWND hwnd, PAINTSTRUCT *pps)\n{\n    PaintSimpleContent(hwnd, pps);\n}\n<\/pre>\n<p>\n        We now have a base program upon which to build.\n    <\/p>\n<p>\n        I&#8217;m sorry this is taking so long to get off the ground. But things finally get interesting\n        in part 4, honest.\n    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing scrollbars is not hard in principle. The basic idea is not that difficult, but there are a lot of small details that need to be ironed out. If you don&#8217;t get the details just right, your program will feel odd in a strange way that you often can&#8217;t pinpoint, much like a subtle background [&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-43053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Managing scrollbars is not hard in principle. The basic idea is not that difficult, but there are a lot of small details that need to be ironed out. If you don&#8217;t get the details just right, your program will feel odd in a strange way that you often can&#8217;t pinpoint, much like a subtle background [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43053","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=43053"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43053\/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=43053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}