change HTA application window size

hta
28,179

Solution 1

<script type="text/javascript">
    window.resizeTo(300,290);
</script>

Solution 2

Javascript and VBScript ways to size the HTA on loading, to 1/4 the screen area (half the height, half the width) and center it - using screen.availWidth and screen.availHeight :

<SCRIPT LANGUAGE="javascript">

function Window_onLoad(){  // resize to quarter of screen area, centered
   window.resizeTo(screen.availWidth/2,screen.availHeight/2);
   window.moveTo(screen.availWidth/4,screen.availHeight/4);
}

window.onload=Window_onLoad;

</SCRIPT>

In VBSScript a Window_onLoad sub will automatically get called any time the HTA starts up (or is refreshed) :

...
</head>

<SCRIPT LANGUAGE="VBScript">

Sub Window_onLoad
    ' resize to quarter of screen area, centered
    window.resizeTo screen.availWidth/2,screen.availHeight/2
    window.moveTo screen.availWidth/4,screen.availHeight/4
End Sub 

</SCRIPT>

<BODY>
...

I've just tested it (Win XP on an old laptop) and there's a quick flicker of the initial larger window before it shrinks to the smaller size, but it's not that bad.

Solution 3

Here is a tip. If the HTA needs to be resized/moved when the hta is opened, then put the resizeTo and moveTo in its own script tag right after the HEAD tag. Then you won't see the flash that happens as a result of the resize/move.

<HTML>  
  <HEAD>
    <SCRIPT type="text/vbscript" language="vbscript">
      ' Do the window sizing early so user doens't see the window move and resize
      Window.resizeTo 330, 130

      Call CenterWindow

      Sub CenterWindow()
        Dim x, y
        With Window.Screen
          x = (.AvailWidth  - 330 ) \ 2
          y = (.AvailHeight - 130 ) \ 2
        End With
        Window.MoveTo x, y
      End Sub
    </SCRIPT>
....

Solution 4

Try setting the HTA Attribute windowstate to minimize

windowstate="minimize"

your resize routine will then set the size you want and force the window display.

first set focus to your window:

    window.focus()
    window.resizeTo(500,500)
    window.moveTo(screen.availWidth-500,0)
Share:
28,179
Remus Rigo
Author by

Remus Rigo

My certifications: MCTS Windows 7, Configuration MCTS Windows Server 2008 R2, Desktop Virtualization MCTS Windows Server 2008 R2, Server Virtualization MCITP Virtualization Administrator on Windows Server 2008 R2 http://about.me/remusrigo/

Updated on May 30, 2020

Comments

  • Remus Rigo
    Remus Rigo about 4 years

    is there any way to change the size of an HTA application?

    thanks