Remus Rigo
Remus Rigo

Reputation: 1464

change HTA application window size

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

thanks

Upvotes: 7

Views: 32578

Answers (5)

GrayFace
GrayFace

Reputation: 1381

This will resize it to fit the content with a bit of extra space to the right and bottom:

<script language="javascript">
    var w = <leftmost element here>.getBoundingClientRect().left + <rightmost element here>.getBoundingClientRect().right;
    var h = <top element here>.getBoundingClientRect().top + <bottom element here>.getBoundingClientRect().bottom;
    // these constants should be big enough to host the window borders and should depend on presence of a scroll bar. I chose random big enough values.
    w += 10;
    h += 25;
    w *= screen.deviceXDPI/100;
    h *= screen.deviceXDPI/100;
    window.resizeTo(w, h);
    window.moveTo((screen.availWidth - w)/2, (screen.availHeight - h)/2);
</script>

Upvotes: 0

Jim Kolb
Jim Kolb

Reputation: 21

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)

Upvotes: 1

cmbro
cmbro

Reputation: 46

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>
....

Upvotes: 3

AjV Jsy
AjV Jsy

Reputation: 6085

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.

Upvotes: 6

Piskvor left the building
Piskvor left the building

Reputation: 92772

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

Upvotes: 14

Related Questions