{"id":93042,"date":"2016-02-17T07:00:00","date_gmt":"2016-02-17T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=93042"},"modified":"2019-03-13T10:30:32","modified_gmt":"2019-03-13T17:30:32","slug":"20160217-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160217-00\/?p=93042","title":{"rendered":"Don&#8217;t just grab the foreground window and host UI on it, redux"},"content":{"rendered":"<p>Some time ago, I advised, &#8220;<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2007\/07\/27\/4072156.aspx\">Don&#8217;t just grab the foreground window and host UI on it<\/a>.&#8221; <\/p>\n<p>Today I learned of another application that failed to heed this advice. When the application&#8217;s installer is launched,&sup1; it calls <code>Get&shy;Foreground&shy;Window<\/code> and uses that window as the owner for its dialogs. In particular, if you install the app by typing <code>setup<\/code> into the <i>Run<\/i> dialog, it would end up hosting all of its dialogs on the <i>Run<\/i> dialog. <\/p>\n<p>This is kind of a problem because the <i>Run<\/i> dialog is ephemeral. After the app is successfully run, the <i>Run<\/i> dialog destroys itself. This in turn causes the installer to crash. <\/p>\n<p>Windows works around this by having the <i>Run<\/i> dialog play complicated foreground games, &#8220;parking&#8221; foreground on another window before launching the installer, and leaving foreground on the parked window long enough for the setup app to call <code>Get&shy;Foreground&shy;Window<\/code>. On the other hand, if the attempt to run the thing you typed fails, the <i>Run<\/i> dialog takes foreground back from the window so it can display the error message. <\/p>\n<p>Fast-forward twenty years. All these foreground games are very fragile, and finally something breaks. The code that tries to steal back foreground in order to display the error message stops working. <\/p>\n<p>The solution: Remove the crazy code to work around this setup program. <\/p>\n<p>The installer in question probably doesn&#8217;t work any more for a ton of other reasons, since it played funny games with <i>Program Manager<\/i> (yes, <i>Program Manager<\/i>) in order to get itself hooked into your shell. <i>Program Manager<\/i> hasn&#8217;t been the shell for  over twenty years. <\/p>\n<p>The risk here is not that somebody is using that twenty-year-old program. The risk is that some program <i>written yesterday<\/i> is relying on this old compatibility hack. <\/p>\n<p>&sup1; Why is it always setup apps who make this mistake? My guess is that companies give the job of writing the installer to the junior developer. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oops, it&#8217;s not there any more.<\/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-93042","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Oops, it&#8217;s not there any more.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93042","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=93042"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93042\/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=93042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=93042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=93042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}