{"id":40463,"date":"2004-02-27T10:13:00","date_gmt":"2004-02-27T10:13:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/02\/27\/the-correct-order-for-disabling-and-enabling-windows\/"},"modified":"2004-02-27T10:13:00","modified_gmt":"2004-02-27T10:13:00","slug":"the-correct-order-for-disabling-and-enabling-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040227-00\/?p=40463","title":{"rendered":"The correct order for disabling and enabling windows"},"content":{"rendered":"<p>If you want to display modal UI, you need to disable the  owner and enable the modal child, and then reverse the  procedure when the modal child is finished.\n  And if you do it wrong, focus will get all messed up.\n  If you are finished with a modal dialog, your temptation  would be to clean up in the following order:<\/p>\n<ul>\n<li>Destroy the modal dialog.  <\/li>\n<li>Re-enable the owner.  <\/li>\n<\/ul>\n<p>  But if you do that, you&#8217;ll find that foreground activation doesn&#8217;t go back  to your owner. Instead, it goes to some random other window.  Explicitly setting activation to the intended owner &#8220;fixes&#8221;  the problem, but you still have all the flicker,  and the Z-order of the interloper window gets all messed up.\n  What&#8217;s going on?\n  When you destroy the modal dialog, you are destroying  the window with foreground activation.  The window manager now needs to find somebody else to give  activation to.  It tries to give it to the dialog&#8217;s owner, but the owner is  <u>still disabled<\/u>,  so the window manager skips it and looks for some other  window, somebody who is not disabled.\n  That&#8217;s why you get the weird interloper window.\n  The correct order for destroying a modal dialog is<\/p>\n<ul>\n<li>Re-enable the owner.  <\/li>\n<li>Destroy the modal dialog.  <\/li>\n<\/ul>\n<p>  This time, when the modal dialog is destroyed, the  window manager looks to the owner and hey this time  it&#8217;s enabled, so it inherits activation.<\/p>\n<p>  No flicker. No interloper.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to display modal UI, you need to disable the owner and enable the modal child, and then reverse the procedure when the modal child is finished. And if you do it wrong, focus will get all messed up. If you are finished with a modal dialog, your temptation would be to clean [&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-40463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you want to display modal UI, you need to disable the owner and enable the modal child, and then reverse the procedure when the modal child is finished. And if you do it wrong, focus will get all messed up. If you are finished with a modal dialog, your temptation would be to clean [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40463","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=40463"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40463\/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=40463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=40463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=40463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}