{"id":42553,"date":"2003-09-11T10:55:00","date_gmt":"2003-09-11T10:55:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/09\/11\/scrollbars-part-10-towards-a-deeper-understanding-of-the-wm_nccalcsize-message\/"},"modified":"2003-09-11T10:55:00","modified_gmt":"2003-09-11T10:55:00","slug":"scrollbars-part-10-towards-a-deeper-understanding-of-the-wm_nccalcsize-message","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030911-00\/?p=42553","title":{"rendered":"Scrollbars part 10 &#8211; Towards a deeper understanding of the WM_NCCALCSIZE message"},"content":{"rendered":"<p>\n        When your window is resized, Windows uses the <code>WM_NCCALCSIZE<\/code> message to\n        determine where your window&#8217;s client area lives inside your window rectangle.\n    <\/p>\n<p>\n        There are two forms of the <code>WM_NCCALCSIZE<\/code> message. The simple form merely\n        takes a window rectangle and returns a client rectangle. This is useful for resizing\n        a window to have a desired client rectangle, taking menu wrapping into account. The <code>AdjustWindowRectEx<\/code> function\n        cannot take menu wrapping into account because it doesn&#8217;t know which menu you are\n        using. (Notice that there is no <code>HMENU<\/code> or <code>HWND<\/code> parameter\n        to <i>AdjustWindowRectEx<\/i>.)\n    <\/p>\n<pre>void\nSetWindowClientSize(HWND hwnd, int cx, int cy)\n{\n    HMENU hmenu = GetMenu(hwnd);\n    RECT rcWindow = { 0, 0, cx, cy };\n    \/*\n     *  First convert the client rectangle to a window rectangle the\n     *  menu-wrap-agnostic way.\n     *\/\n    AdjustWindowRectEx(&amp;rcWindow, GetWindowStyle(hwnd), hmenu != NULL,\n                       GetWindowExStyle(hwnd));\n    \/*\n     *  If there is a menu, then check how much wrapping occurs\n     *  when we set a window to the width specified by AdjustWindowRect\n     *  and an infinite amount of height.  An infinite height allows\n     *  us to see every single menu wrap.\n     *\/\n    if (hmenu) {\n        RECT rcTemp = rcWindow;\n        rcTemp.bottom = 0x7FFF;     \/* \"Infinite\" height *\/\n        SendMessage(hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&amp;rcTemp);\n        \/*\n         *  Adjust our previous calculation to compensate for menu\n         *  wrapping.\n         *\/\n        rcWindow.bottom += rcTemp.top;\n    }\n    SetWindowPos(hwnd, NULL, 0, 0, rcWindow.right - rcWindow.left,\n                 rcWindow.bottom - rcWindow.top, SWP_NOMOVE | SWP_NOZORDER);\n}\n<\/pre>\n<p>\n        <b>Exercise<\/b>: Explain why we used 0x7FFF to represent infinite height.\n    <\/p>\n<p>\n        <b>Exercise<\/b>: Explain the line <code>rcWindow.bottom += rcTemp.top<\/code>.\n    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>When your window is resized, Windows uses the WM_NCCALCSIZE message to determine where your window&#8217;s client area lives inside your window rectangle. There are two forms of the WM_NCCALCSIZE message. The simple form merely takes a window rectangle and returns a client rectangle. This is useful for resizing a window to have a desired client [&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-42553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When your window is resized, Windows uses the WM_NCCALCSIZE message to determine where your window&#8217;s client area lives inside your window rectangle. There are two forms of the WM_NCCALCSIZE message. The simple form merely takes a window rectangle and returns a client rectangle. This is useful for resizing a window to have a desired client [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42553","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=42553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/42553\/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=42553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=42553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=42553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}