{"id":66653,"date":"2006-08-18T16:03:00","date_gmt":"2006-08-18T16:03:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/08\/18\/how-can-i-minimize-or-hide-an-html-application-for-30-seconds\/"},"modified":"2006-08-18T16:03:00","modified_gmt":"2006-08-18T16:03:00","slug":"how-can-i-minimize-or-hide-an-html-application-for-30-seconds","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-minimize-or-hide-an-html-application-for-30-seconds\/","title":{"rendered":"How Can I Minimize or Hide an HTML Application for 30 Seconds?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I minimize or hide an HTA for 30 seconds?<BR><BR>&#8212; MF<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, MF. You know, with the possible exception of baseball, the Scripting Guy who writes this column rarely claims to know much about anything. And for good reason: every time he <I>thinks<\/I> he knows something, well \u2026.<\/P>\n<P>Take your question, for example. Minimize or hide an HTA? No problem, he thought. After all, HTA\u2019s have a property named windowStyle that can be used to configure an HTA to run minimized, maximized, or in a normal window. And if that\u2019s not good enough for you, then you can simply set the Visible property of the HTA to False. Take your pick.<\/P>\n<P>So, sure, take your pick; just don\u2019t expect either choice to solve your problem. As it turns out, HTAs don\u2019t <I>have<\/I> a Visible property, something this Scripting Guy would have realized had he bothered to think about this question for a second. As for the windowStyle property, well, that property <I>does<\/I> exist; however, it can be configured only at startup time. After the HTA is up and running you can no longer change the windowStyle property; that means you can\u2019t easily switch between, say, a minimized window and a normal window.<\/P>\n<P>Uh-oh.<\/P>\n<P>In other words, this Scripting Guy is no genius. (Well, the Scripting Editor thinks he is. But he\u2019s really not.)<\/P>\n<TABLE id=\"EKD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Editor\u2019s Note:<\/B> We\u2019re not sure where the Scripting Guy got the impression <I>anyone<\/I> thinks he\u2019s a genius, let alone the Scripting Editor. Could it have been the baffled looks, or the comments like \u201cWhat are you talking about?\u201d and \u201cAre you out of your mind?\u201d We\u2019re not sure, but he\u2019s on vacation this week and won\u2019t see this, so if it makes him happy we\u2019ll let him remain in his own imaginary little world. And we\u2019ll know that the next time we say to him \u201cDo you <I>have<\/I> a brain?\u201d he\u2019s taking it as a compliment.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>On the other hand, there <I>is<\/I> one advantage to being dumb: you\u2019re not smart enough to know when you\u2019re licked. Maybe we can\u2019t minimize or hide an HTA, but we <I>can<\/I> do this:<\/P><PRE class=\"codeSample\">&lt;html&gt;<\/p>\n<p>&lt;SCRIPT Language=&#8221;VBScript&#8221;&gt;<\/p>\n<p>    Dim intLeft\n    Dim intTop<\/p>\n<p>    Sub HideWindow\n        intLeft = window.screenLeft\n        intTop = window.screenTop\n        window.moveTo -2000,-2000\n        idTimer = window.setTimeout(&#8220;ShowWindow&#8221;, 5000, &#8220;VBScript&#8221;)\n    End Sub<\/p>\n<p>    Sub ShowWindow\n        window.moveTo intLeft,intTop\n        window.clearTimeout(idTimer)\n    End Sub\n&lt;\/SCRIPT&gt;<\/p>\n<p>&lt;body&gt;\n    &lt;input type=&#8221;button&#8221; value=&#8221;Hide Window&#8221; onClick=&#8221;HideWindow&#8221;&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/PRE>\n<P>If you run this script and click the button labeled <B>Hide Window<\/B>, the HTA will disappear. However, that\u2019s not because we\u2019ve minimized the window or because we\u2019ve made the application invisible; instead, we\u2019ve simply moved the HTA clear off the screen. After a five-second pause (a time interval you can modify as needed), we restore the window to its previous location. Not bad, huh?<\/P>\n<P>Let\u2019s see if we can figure out how this thing works. To begin with, the body of the HTA contains just one thing &#8212; a single button labeled <B>Hide Window<\/B>:<\/P><PRE class=\"codeSample\">&lt;input type=&#8221;button&#8221; value=&#8221;Hide Window&#8221; onClick=&#8221;HideWindow&#8221;&gt;\n<\/PRE>\n<P>Click this button, and you\u2019ll run a subroutine named HideWindow. That subroutine looks like this:<\/P><PRE class=\"codeSample\">Sub HideWindow\n    intLeft = window.screenLeft\n    intTop = window.screenTop\n    window.moveTo -2000,-2000\n    idTimer = window.setTimeout(&#8220;ShowWindow&#8221;, 5000, &#8220;VBScript&#8221;)\nEnd Sub\n<\/PRE>\n<P>As you can see, we don\u2019t really do much in this HTA. We start out by assigning values to a pair of global variables named intLeft and intTop:<\/P><PRE class=\"codeSample\">intLeft = window.screenLeft\nintTop = window.screenTop\n<\/PRE>\n<P>What we\u2019re doing here is making a note of the upper (<B>window.screenTop<\/B>) left-hand (<B>window.screenLeft<\/B>) corner of the HTA window. Why do we do that? That\u2019s easy: by knowing the location of the upper left-hand corner we\u2019ll be able to restore the window to its current spot. After grabbing this information we then move the window off the screen:<\/P><PRE class=\"codeSample\">window.moveTo -2000,-2000\n<\/PRE>\n<P>How do we know this moves the window off the screen? Well, the upper left-hand corner of the screen has the coordinates 0, 0. A window with coordinates -2000, -2000 is going to be <I>way<\/I> off the screen.<\/P>\n<P>With the window no longer visible this would probably be the spot where you would run whatever code you need the HTA to run. Instead of putting some phony-baloney code in here we simply set a timer that pauses the HTA for 5 seconds (5,000 milliseconds) and then calls a subroutine named ShowWindow:<\/P><PRE class=\"codeSample\">idTimer = window.setTimeout(&#8220;ShowWindow&#8221;, 5000, &#8220;VBScript&#8221;)\n<\/PRE>\n<TABLE id=\"EDF\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Did someone say they didn\u2019t understand how the timer-setting code works? If so, take a look at this <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/mar06\/hey0330.mspx\"><B>Hey, Scripting Guy!<\/B><\/A> column for more information.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>And what does the ShowWindow subroutine do? Actually, it does two things. First, it moves the window back to its original location:<\/P><PRE class=\"codeSample\">window.moveTo intLeft,intTop\n<\/PRE>\n<P>And then it clears the timer:<\/P><PRE class=\"codeSample\">window.clearTimeout(idTimer)\n<\/PRE>\n<P>Do we really need to clear the timer? Well, it\u2019s a pretty good idea; otherwise every 5 seconds the timer is going to fire and move the window back to its original position. <\/P>\n<P>Give this a try, MF, and see if it helps; we think it will. And that\u2019s a good point: imagine what a cool solution we could have come up with had we actually know what we were doing.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I minimize or hide an HTA for 30 seconds?&#8212; MF Hey, MF. You know, with the possible exception of baseball, the Scripting Guy who writes this column rarely claims to know much about anything. And for good reason: every time he thinks he knows something, well \u2026. Take your question, [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2,3,4,5,30],"class_list":["post-66653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-running","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I minimize or hide an HTA for 30 seconds?&#8212; MF Hey, MF. You know, with the possible exception of baseball, the Scripting Guy who writes this column rarely claims to know much about anything. And for good reason: every time he thinks he knows something, well \u2026. Take your question, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=66653"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=66653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}