使用 QTP 读取屏幕的分辨率



在初始化脚本时,我必须读取屏幕的分辨率,以便知道如何调整浏览器窗口大小。

有什么想法吗?

提前感谢!

下面是一些代码,可以获取主监视器或所有多个监视器的分辨率。此外,最后一个函数返回一个布尔值,表示您是否有多个监视器。

'*******************************************************************
'TotalScreenWidth & TotalScreenHeight
'by Michael Innes
'October 2012
'Intended for getting the total resolution when you have multiple monitors
'Returns the width and the height (respectively) across all the screens.
Function TotalScreenWidth()
    TotalScreenWidth = Window("regexpwndtitle:=Program Manager").GetROProperty("width")
End Function
Function TotalScreenHeight()
    TotalScreenHeight = Window("regexpwndtitle:=Program Manager").GetROProperty("height")
End Function

'*******************************************************************
'ScreenWidth & ScreenHeight
'by Michael Innes
'October 2012
'Retrieves the width and height (respectively) of the primary screen (the screen that the taskbar is on)
'This only works if the taskbar is at the bottom of the screen
Function ScreenWidth()
    ScreenWidth = Window("object class:=Shell_TrayWnd").GetROProperty("width")
End Function
Function ScreenHeight()
    ScreenHeight = Window("object class:=Shell_TrayWnd").GetROProperty("height") + Window("object class:=Shell_TrayWnd").GetROProperty("y")
End Function

'*******************************************************************
'MultipleMonitors
'by Michael Innes
'October 2012
'Returns a boolean that determines if the computer has multiple monitors attached.
'This only works if the taskbar is at the bottom of the left-most screen.
'If the taskbar is on the right-most monitor, this function will incorrectly report the multiple monitors as being False.
Function MultipleMonitors()
    MultipleMonitors = Eval((screenWidth <> TotalScreenWidth) OR (screenHeight <> TotalScreenHeight))
End Function

这实际上非常简单,找到桌面窗口并获取其尺寸。

width = Window("text:=Program Manager").GetROProperty("width")
height = Window("text:=Program Manager").GetROProperty("height")
Print width & ", " & height

这适用于单个显示器,我还没有检查当您有多个显示器时会发生什么。

最新更新