{"id":40493,"date":"2004-02-24T08:47:00","date_gmt":"2004-02-24T08:47:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/02\/24\/whats-so-special-about-the-desktop-window\/"},"modified":"2004-02-24T08:47:00","modified_gmt":"2004-02-24T08:47:00","slug":"whats-so-special-about-the-desktop-window","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040224-00\/?p=40493","title":{"rendered":"What&#039;s so special about the desktop window?"},"content":{"rendered":"<p>The window returned by  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/WinUI\/WindowsUserInterface\/Windowing\/Windows\/WindowReference\/WindowFunctions\/GetDesktopWindow.asp\">  GetDesktopWindow()<\/a> is very special,  and I see people abusing it all over the place.\n  For example, many functions in the shell accept a window handle  parameter to be used in case UI is needed.  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/reference\/ifaces\/ishellfolder\/EnumObjects.asp\">  IShellFolder::EnumObjects<\/a>, for example.\n  What happens if you pass GetDesktopWindow()?\n  If UI does indeed need to be displayed, you hang the system.\n  Why?<\/p>\n<ul>\n<li>A modal dialog disables its owner.  <\/li>\n<li>Every window is a descendant of the desktop.  <\/li>\n<li>When a window is disabled, all its descendants are also      disabled.  <\/li>\n<\/ul>\n<p>  Put this together:  If the owner of a modal dialog is the desktop,  then the desktop becomes disabled, which disables all of its  descendants.  In other words, it disables every window in the  system.  Even the one you&#8217;re trying to display!\n  You also don&#8217;t want to pass GetDesktopWindow() as your  hwndParent.  If you create a child window whose parent is  GetDesktopWindow(), your window is now glued to the desktop  window.  If your window then calls something like  MessageBox(), well that&#8217;s a modal dialog, and then the rules  above kick in and the desktop gets disabled and the machine  is toast.\n  So what window do you pass if you don&#8217;t have a window?\n  Pass NULL.  To the window manager, a parent of NULL means  &#8220;Create this window without an owner.&#8221;  To the shell, a UI window  of NULL typically means &#8220;Do not display UI,&#8221; which is likely  what you wanted anyway.<\/p>\n<p>  Be careful, though:  If your thread does have a top-level unowned  window, then creating a second such window modally will create much  havoc if the user switches to and interacts with the first window.  If you have a window, then use it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The window returned by GetDesktopWindow() is very special, and I see people abusing it all over the place. For example, many functions in the shell accept a window handle parameter to be used in case UI is needed. IShellFolder::EnumObjects, for example. What happens if you pass GetDesktopWindow()? If UI does indeed need to be displayed, [&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-40493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The window returned by GetDesktopWindow() is very special, and I see people abusing it all over the place. For example, many functions in the shell accept a window handle parameter to be used in case UI is needed. IShellFolder::EnumObjects, for example. What happens if you pass GetDesktopWindow()? If UI does indeed need to be displayed, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40493","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=40493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40493\/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=40493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=40493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=40493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}