{"id":23803,"date":"2008-01-16T10:00:00","date_gmt":"2008-01-16T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/01\/16\/use-wm_windowposchanging-to-intercept-window-state-changes\/"},"modified":"2008-01-16T10:00:00","modified_gmt":"2008-01-16T10:00:00","slug":"use-wm_windowposchanging-to-intercept-window-state-changes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080116-00\/?p=23803","title":{"rendered":"Use WM_WINDOWPOSCHANGING to intercept window state changes"},"content":{"rendered":"<p>\nThe <code>WM_WINDOWPOSCHANGING<\/code> message is sent early in the\nwindow state changing process,\nunlike\n<code>WM_WINDOWPOSCHANGED<\/code>,\nwhich tells you about what already happened.\nA crucial difference (aside from the timing)\nis that you can influence the state change\nby handling the <code>WM_WINDOWPOSCHANGING<\/code> message\nand modifying the <code>WINDOWPOS<\/code> structure.\n<\/p>\n<p>\nHere&#8217;s an example that prevents the window from being resized.\n<\/p>\n<pre>\nBOOL OnWindowPosChanging(HWND hwnd, WINDOWPOS *pwp)\n{\n    pwp-&gt;flags |= SWP_NOSIZE;\n    \/* Continue with default handling *\/\n    return FORWARD_WM_WINDOWPOSCHANGING(hwnd, pwp, DefWindowProc);\n}\nHANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, OnWindowPosChanging);\n<\/pre>\n<p>\nBefore the <code>WM_WINDOWPOSCHANGING<\/code> message was invented,\nprograms had to enforce window size constraints\ninside their <code>WM_SIZE<\/code> and <code>WM_MOVE<\/code> handlers,\nbut since those messages are sent <i>after<\/i> the change is complete,\nthe result was flicker as the window changed to one size,\nthen the <code>WM_SIZE<\/code> handler resized it to a better size.\nIntercepting the window size change in <code>WM_WINDOWPOSCHANGING<\/code>\nallows you to enforce constraints before the sizing happens, thereby\navoiding flicker.\n<\/p>\n<p>\nThe <code>WM_WINDOWPOSCHANGING<\/code> and\n<code>WM_WINDOWPOSCHANGED<\/code> pair of messages is just one example\nof the more general <code>*CHANGING<\/code>\/<code>*CHANGED<\/code> pattern.\n(Other examples are <code>WM_STYLECHANGING<\/code>\/<code>WM_STYLECHANGED<\/code>\nand <code>LVN_ITEMCHANGING<\/code>\/<code>LVN_ITEMCHANGED<\/code>.)\nThe <code>*CHANGING<\/code> half is sent before\nthe change takes place, and as a general rule,\nyou can change the parameters of the notification to enforce some\ntype of constraint.\nAfter you return from the <code>*CHANGING<\/code> notification,\nthe actual change takes place, and then you receive a\n<code>*CHANGED<\/code> to indicate that the change is complete.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The WM_WINDOWPOSCHANGING message is sent early in the window state changing process, unlike WM_WINDOWPOSCHANGED, which tells you about what already happened. A crucial difference (aside from the timing) is that you can influence the state change by handling the WM_WINDOWPOSCHANGING message and modifying the WINDOWPOS structure. Here&#8217;s an example that prevents the window from being [&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-23803","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The WM_WINDOWPOSCHANGING message is sent early in the window state changing process, unlike WM_WINDOWPOSCHANGED, which tells you about what already happened. A crucial difference (aside from the timing) is that you can influence the state change by handling the WM_WINDOWPOSCHANGING message and modifying the WINDOWPOS structure. Here&#8217;s an example that prevents the window from being [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23803","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=23803"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23803\/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=23803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=23803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=23803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}