如何将HTA窗口居中,使其位于屏幕中心,而不管HTA大小的屏幕分辨率如何,我有以下内容:
</head>
<script>
Sub DoResize 'Do not use Window_Onload
window.resizeTo 800,600
strComputer = "."
Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
intLeft = (intHorizontal - 800) / 2
intTop = (intVertical - 600) / 2
window.moveTo intLeft, intTop
End Sub
DoResize() 'Run the subroutine to position the containing window (your HTA dialog) before the body is rendered.
</script>
<body>但是如果我改变屏幕分辨率,它就不能工作,它会调整HTA窗口的大小。
问:如何将HTA移动到屏幕中心,而不考虑屏幕分辨率的HTA大小。
发布于 2014-03-10 18:05:51
为此使用WMI有点过火了。您可以使用screen对象代替:
window.resizeTo (800, 600);
window.moveTo((screen.width - 800) / 2, (screen.height - 600) / 2);如果您想在开始时调整窗口的大小,请将上面的行放在head部分中的(JS) head标记中,甚至在<hta: application>标记之前,或者在事件处理程序中或需要它的任何地方使用代码。
如果要将任务栏的高度排除在中心区之外,可以使用screen.availHeight而不是screen.height。
发布于 2018-02-27 02:17:04
var winWidth = 800, winHeight = 600;
window.resizeTo(winWidth, winHeight);
window.moveTo((screen.width - winWidth) / 2, (screen.height - winHeight) / 2);https://stackoverflow.com/questions/22301262
复制相似问题