{"id":97025,"date":"2017-09-14T07:00:00","date_gmt":"2017-09-14T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97025"},"modified":"2019-03-13T01:16:49","modified_gmt":"2019-03-13T08:16:49","slug":"20170914-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170914-00\/?p=97025","title":{"rendered":"Why is my window unexpectedly becoming topmost?"},"content":{"rendered":"<p>A customer had a problem where one of their program&#8217;s windows was somehow receiving the <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code> extended window style, thereby becoming topmost. The scenario was that they created a popup window with the <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code> extended style, and subsequently opened a document window. If they destroyed the popup window before creating the document window, then everything was fine. But if they created the document window before destroying the popup window, then their main app magically gained the <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code> extended style. Their investigation revealed that nobody was calling <code>Set&shy;Window&shy;Long<\/code> with <code>GWL_<\/code><code>EXSTYLE<\/code> and <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code>.&sup1; Are there other ways that a window can become topmost? <\/p>\n<p>One way that a window can become topmost is if it is created with the <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code> extended style. <\/p>\n<p>Another way that a window can become topmost is if you call <code>Set&shy;Window&shy;Pos<\/code> and pass <code>HWND_<\/code><code>TOP&shy;MOST<\/code> as the <code>hwnd&shy;Insert&shy;After<\/code>. <\/p>\n<p>Yet another way that a window can become topmost is if you pass a topmost window as the <code>hwnd&shy;Insert&shy;After<\/code>. <\/p>\n<p>Armed with this information, the customer did some more investigation and reported back: They found a call to <code>Set&shy;Window&shy;Pos<\/code> that was making the window topmost. <\/p>\n<p>Mystery solved! <\/p>\n<p>&sup1; Not that anybody should be doing that anyway. <a HREF=\"https:\/\/msdn.microsoft.com\/library\/windows\/desktop\/ff700543(v=vs.85).aspx\">The documentation for the <code>WS_<\/code><code>EX_<\/code><code>TOP&shy;MOST<\/code> extended style<\/a> says that you shouldn&#8217;t be manipulating the extended style bit directly. &#8220;To add or remove this style, use the <code>Set&shy;Window&shy;Pos<\/code> function.&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a few places where the system will auto-topmost a window.<\/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-97025","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>There are a few places where the system will auto-topmost a window.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97025","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=97025"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97025\/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=97025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}