Monitor Resolution and DPI with QTP/UFT


Monitor Resolution and DPI with QTP/UFT
”Monitor resolution. If you have multiple monitors then it add the width of multiple monitors,
”Returns total width of the monitors and the height of the screens.
screenWidth = Window(“regexpwndtitle:=Program Manager”).GetROProperty(“width”)
screenHeight = Window(“regexpwndtitle:=Program Manager”).GetROProperty(“height”)
MsgBox screenWidth &“x”& screenHeight

”Retrieves the width and height of the primary screen (has the taskbar for windows 7)
screenWidth = Window(“object class:=Shell_TrayWnd”).GetROProperty(“width”)
screenHeight = Window(“object class:=Shell_TrayWnd”).GetROProperty(“height”) + Window(“object class:=Shell_TrayWnd”).GetROProperty(“y”)
MsgBox screenWidth &“x”& screenHeight

”For current Monitor resolution
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery (“Select * from Win32_VideoController”)

For Each objItem in colItems
print “Current Horizontal Resolution: “ & objItem.CurrentHorizontalResolution
print “Current Vertical Resolution: “ & objItem.CurrentVerticalResolution
Next

”Run from Control Panel 
Systemutil.run “control.exe”,“desk.cpl”        ”’Screen resolution
Systemutil.run “DpiScaling.exe”        ”’Font size and DPI

”### Works For Laptop but does not work for Laptop extended monitor
”### Also works For Desktop for single monitor
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery _
(“Select * From Win32_DisplayConfiguration”)

For Each objItem in colItems
Print “Name: “ & objItem.DeviceName
Print “Color depth: “ & objItem.BitsPerPel
Print “Horizontal resolution: “ & objItem.PelsWidth
Print “Vertical resolution: “ & objItem.PelsHeight
Next
”#### END ######

”’Find the Desktop DPI is set to smaller 100% or Medium 120%(default)
”’Some Desktop application appears on screen smaller or larger by Desktop DPI
”’If use application’s Y, X cordinate it change by DPI not resolution
”’Finaly set it to Environment Variable, so you can call as many times you want in RunTime
Dim windowsDPI
windowsDPI = ReadReg(“HKEY_CURRENT_USER\Control Panel\Desktop\LogPixels”)”’Windows Desktop DPI
‘msgbox windowsDPI
Environment(“desktopDPI”) = windowsDPI
Function ReadReg(RegPath)
Dim objRegistry, Key
Set objRegistry = CreateObject(“Wscript.shell”)
Key = objRegistry.RegRead(RegPath)
ReadReg = Key
msgbox true
End Function
”’For Example in PowerBuilder Application, sometimes DropDown is used inside a DataWindow
”’ The DropDown contains another DataWindow that is not visible until DropDown is clicked by X, and Y
”’For DPI smaller 100% you can use SelectCellData but if it is Medium 120% then sometimes it does not work
”’Also to create a loop you have to make the DropDown DataWindow visible
If Environment(“desktopDPI”) = 96 Then
PbWindow(“pb_window_name”).PbWindow(“pb_window_name”).PbDataWindow(“pb_DataWindow_name”).Click 342,41
ElseIf Environment(“desktopDPI”) = 120 Then
PbWindow(“pb_window_name”).PbWindow(“pb_window_name”).PbDataWindow(“pb_DataWindow_name”).Click 428,51
Else
Reporter.ReportEvent micWarning, “Desktop Screen”“Desktop DPI is more than 120%” & vbCrLf & “Change DPI from the Control Panel > Display”
End If

Advertisements

One thought on “Monitor Resolution and DPI with QTP/UFT

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s