{"id":24863,"date":"2007-10-08T10:00:00","date_gmt":"2007-10-08T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/10\/08\/which-windows-appear-in-the-alttab-list\/"},"modified":"2007-10-08T10:00:00","modified_gmt":"2007-10-08T10:00:00","slug":"which-windows-appear-in-the-alttab-list","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20071008-00\/?p=24863","title":{"rendered":"Which windows appear in the Alt+Tab list?"},"content":{"rendered":"<p>\nCommenter Phil Quirk\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#416509\">\nwants to know what the rules are for determining which windows\nappear in the Alt+Tab list<\/a>.\nIt&#8217;s actually pretty simple although hardly anything you&#8217;d be able to guess\non your own.\n<b>Note<\/b>: The details of this algorithm are an implementation detail.\nIt can change at any time, so don&#8217;t rely on it.\nIn fact, it already changed with Flip and Flip3D;\nI&#8217;m just talking about the Classic Alt+Tab window here.\n<\/p>\n<p>\nFor each visible window,\nwalk up its owner chain until you find the root owner.\nThen walk back down the visible last active popup chain until you find\na visible window.\nIf you&#8217;re back to where you&#8217;re started, then put the window in the\nAlt+Tab list.\nIn pseudo-code:\n<\/p>\n<pre>\nBOOL IsAltTabWindow(HWND hwnd)\n{\n \/\/ Start at the root owner\n HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);\n \/\/ See if we are the last active visible popup\n HWND hwndTry;\n while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {\n  if (IsWindowVisible(hwndTry)) break;\n  hwndWalk = hwndTry;\n }\n return hwndWalk == hwnd;\n}\n<\/pre>\n<p>\nThe purpose of this algorithm is to assign the most meaningful\nrepresentative winow from each cluster of windows\nrelated by ownership.\n(Notice that the algorithm doesn&#8217;t care whether the owned window is\nmodal or non-modal.)\n<\/p>\n<p>\nAt least that&#8217;s the simple rule if you&#8217;re not playing crazy window\nstyle games.\nThe <code>WS_EX_TOOLWINDOW<\/code> and <code>WS_EX_APPWINDOW<\/code>\nextended styles were created so people can play games and put their\nwindow in the Alt+Tab list or take it out even if the simple rule\nwould normally have decided otherwise.\nThis is one of those\n&#8220;Okay, if you think you&#8217;re smarter than Windows, here&#8217;s your chance\nto prove it&#8221; options.\nPersonally, I would avoid them since it makes your window behave\ndifferently from the rest of the windows in the system.\n<\/p>\n<p>\nA window with the\n<code>WS_EX_TOOLWINDOW<\/code> extended style is treated as if it\nweren&#8217;t visible, even if it is.\nA window with the\n<code>WS_EX_APPWINDOW<\/code> extended style is treated as if it\nhas no owner, even if it does.\n<\/p>\n<p>\nOnce you start adding these extended styles, you enter the world\nof &#8220;I&#8217;m trying to work around the rules&#8221; and the result is typically\neven worse confusion than what you had without them.\n<\/p>\n<p>\nI&#8217;m not sure what the original commenter is getting at.\nThe window hierarchy described in the suggestion\n(which doesn&#8217;t make it so much a suggestion as it is a request\nfor me to debug their problem) says that window&nbsp;C is\nmodal on both windows A&nbsp;and&nbsp;B, which doesn&#8217;t make\nsense to me, since a window has only one owner.\n<\/p>\n<p>\nThe algorithm for choosing the Alt+Tab representative from each\ncluster of windows may not be the best, but it&#8217;s what we have.\nI wouldn&#8217;t be surprised if the details are tweaked from time to time.\nNo, wait, let me rephrase that.\nI <i>know<\/i> that the details are tweaked from time to time.\nThe spirit of the operation is preserved\n(to show the windows the user can switch to, using the most &#8220;natural&#8221;\ncandidate for each cluster of windows),\nbut the specific details may be fined-tuned as the concept of &#8220;naturalness&#8221;\nis refined.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Phil Quirk wants to know what the rules are for determining which windows appear in the Alt+Tab list. It&#8217;s actually pretty simple although hardly anything you&#8217;d be able to guess on your own. Note: The details of this algorithm are an implementation detail. It can change at any time, so don&#8217;t rely on it. [&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-24863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter Phil Quirk wants to know what the rules are for determining which windows appear in the Alt+Tab list. It&#8217;s actually pretty simple although hardly anything you&#8217;d be able to guess on your own. Note: The details of this algorithm are an implementation detail. It can change at any time, so don&#8217;t rely on it. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24863","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=24863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24863\/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=24863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=24863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=24863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}