无论 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 移动到屏幕中心。
最佳答案
为此使用 WMI 有点矫枉过正。您可以使用 screen
对象代替:
window.resizeTo (800, 600);
window.moveTo((screen.width - 800) / 2, (screen.height - 600) / 2);
如果你想在开始时调整窗口大小,将上面的行放在 (JS) script
中head
中的标签部分,甚至在 <hta: application>
之前标记,或在事件处理程序中或任何需要的地方使用代码。
如果你想将任务栏的高度排除在居中区域之外,你可以使用screen.availHeight
而不是 screen.height
.
关于html - 使 hta 窗口居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22301262/