6

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

thanks

Remus Rigo
  • 1,454
  • 8
  • 34
  • 60

4 Answers4

13
<script type="text/javascript">
    window.resizeTo(300,290);
</script>
Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
5

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.

AjV Jsy
  • 5,799
  • 4
  • 34
  • 30
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>
....
cmbro
  • 46
  • 1
  • Thanks but I've just tried that and it didn't work for me. The resize/move doesn't work unless it's after the `, and by then it seems it's too late because I still get the flicker. – AjV Jsy Aug 06 '15 at 17:45
1

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)
Jim Kolb
  • 21
  • 5