{"id":68933,"date":"2005-09-19T14:56:00","date_gmt":"2005-09-19T14:56:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/09\/19\/how-can-i-specify-a-window-size-for-my-hta\/"},"modified":"2005-09-19T14:56:00","modified_gmt":"2005-09-19T14:56:00","slug":"how-can-i-specify-a-window-size-for-my-hta","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-specify-a-window-size-for-my-hta\/","title":{"rendered":"How Can I Specify a Window Size for My HTA?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I specify a particular window size for my HTA?<BR><BR>&#8212; RN<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, RN. We can\u2019t speak for Dear Abby, Ann Landers or any other daily columnist, but the Scripting Guys are always on the lookout for a question that can be answered using a single line of code. That\u2019s the Holy Grail for daily columnists: one and done. And, to the best of our knowledge, neither Dear Abby nor Ann Landers have <I>ever<\/I> answered a question using just a single line of code. It\u2019s always been our dream to beat them to the punch. <\/P>\n<P>And now we have. How can you specify a particular window size for an HTA? Here\u2019s how:<\/P><PRE class=\"codeSample\">window.resizeTo 400,250\n<\/PRE>\n<P>There you go: add that line of code to your HTA and the next time you start the thing the window will automatically be sized to 400 pixels wide by 250 pixels high.<\/P>\n<P>What\u2019s that? Well, OK, sure, if you want to be <I>picky<\/I> about it. Admittedly, you can\u2019t just add that line of code anywhere within your HTA; instead, you\u2019ll need to create a Window_onLoad subroutine and place the code inside there:<\/P><PRE class=\"codeSample\">Sub Window_onLoad\n    window.resizeTo 400,250\nEnd Sub\n<\/PRE>\n<P>As you probably know, Window_onLoad is a special subroutine designed to run any time the HTA starts up or is refreshed. If you place the <B>resizeTo<\/B> method inside Window_onLoad then that line of code will execute each time the HTA starts. In turn, that means that the window will be appropriately sized each time the HTA starts.<\/P>\n<P>Here\u2019s a more \u201ccomplete\u201d HTA, one that does nothing other than show up in a window 400 pixels by 250 pixels:<\/P><PRE class=\"codeSample\">&lt;SCRIPT LANGUAGE=&#8221;VBScript&#8221;&gt;<\/p>\n<p>    Sub Window_onLoad\n        window.resizeTo 400,250\n    End Sub <\/p>\n<p>&lt;\/SCRIPT&gt;<\/p>\n<p>&lt;BODY&gt;\n&lt;\/BODY&gt;\n<\/PRE>\n<P>Simply copy the code, paste it into Notepad, and then save the file with a .HTA file extension. If you aren\u2019t sure what happens then, well, you might want to take a look at <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/htas\/tutorial1.mspx\" target=\"_blank\"><B>Part 1<\/B><\/A> in our series on creating HTAs. (Which, in case you\u2019re wondering, is short for HTML Applications.)<\/P>\n<P>So, yes, <I>technically<\/I>, we really needed to add three lines of code in order to get this to work:<\/P><PRE class=\"codeSample\">Sub Window_onLoad\n    window.resizeTo 400,250\nEnd Sub\n<\/PRE>\n<P>But do us a favor, OK? The next time Ann Landers asks, tell her we answered this question with just a single line of code. We can\u2019t wait to see the look on her face when she hears <I>that<\/I>.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I specify a particular window size for my HTA?&#8212; RN Hey, RN. We can\u2019t speak for Dear Abby, Ann Landers or any other daily columnist, but the Scripting Guys are always on the lookout for a question that can be answered using a single line of code. That\u2019s the Holy [&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":[3,4,5,30],"class_list":["post-68933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I specify a particular window size for my HTA?&#8212; RN Hey, RN. We can\u2019t speak for Dear Abby, Ann Landers or any other daily columnist, but the Scripting Guys are always on the lookout for a question that can be answered using a single line of code. That\u2019s the Holy [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68933","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=68933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68933\/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=68933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}