{"id":110283,"date":"2024-09-19T07:00:00","date_gmt":"2024-09-19T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=110283"},"modified":"2024-09-19T10:58:09","modified_gmt":"2024-09-19T17:58:09","slug":"20240919-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240919-00\/?p=110283","title":{"rendered":"My window has the <CODE>WS_<WBR>EX_<WBR>NOACTIVATE<\/CODE> extended style, but it got activated anyway"},"content":{"rendered":"<p>If you set the <code>WS_<wbr \/>EX_<wbr \/>NOACTIVATE<\/code> extended window style, Windows won&#8217;t activate the window when it is clicked on, Windows will skip the window when looking for a new window to activate when the active window is destroyed, and the window won&#8217;t show up in <kbd>Alt<\/kbd>+<kbd>Tab<\/kbd> or the taskbar by default. You can still activate it programmatically, usually by calling <code>Set\u00adActive\u00adWindow<\/code> or <code>Set\u00adForeground\u00adWindow<\/code>.<\/p>\n<p>If you override the default and make the window appear in <kbd>Alt<\/kbd>+<kbd>Tab<\/kbd> and the taskbar, then those UI surfaces will call <code>Set\u00adForeground\u00adWindow<\/code> when the window is selected, so that&#8217;s one way an end-user can activate a no-activate window.<\/p>\n<p>But there&#8217;s one oft-overlooked way the user can activate a no-activate window: Use the &#8220;Activate a window by hovering over it with the mouse&#8221; setting (known programmatically as &#8220;active window tracking&#8221;), and hover over the window.<\/p>\n<p>When this happens, the &#8220;active window tracking&#8221; code doesn&#8217;t check the <code>WS_<wbr \/>EX_<wbr \/>NOACTIVATE<\/code> style.\u00b9 It goes directly to sending the window a <code>WM_<wbr \/>MOUSE\u00adACTIVATE<\/code> message to ask whether the window should be activated, and <code>Def\u00adWindow\u00adProc<\/code> will say &#8220;Sure, activate me!&#8221;<\/p>\n<p>If you want to prevent the window from being activated by mouse hover, you need to handle the <code>WM_<wbr \/>MOUSE\u00adACTIVATE<\/code> message and return <code>MA_<wbr \/>NO\u00adACTIVATE<\/code> or <code>MA_<wbr \/>NO\u00adACTIVATE\u00adAND\u00adEAT<\/code>, depending on what you want to happen to the mouse event.<\/p>\n<p>\u00b9 This is arguably an oversight in the activate window tracking feature code when it was originally written.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, at least it wasn&#8217;t activated by a click.<\/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-110283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Well, at least it wasn&#8217;t activated by a click.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110283","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=110283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110283\/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=110283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=110283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=110283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}