change HTA application window size

孤者浪人 提交于 2020-01-01 11:32:51

问题


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

thanks


回答1:


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



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




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



回答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)


来源:https://stackoverflow.com/questions/3166195/change-hta-application-window-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!