Can anyone tell me how to highlight an object using highlight method with different border color?
Question ID: 106006
1
0

Can anyone tell me how to highlight an object using highlight method with different border color?

Marked as spam
Posted by (Questions: 386, Answers: 64)
Asked on April 22, 2015 5:40 pm
185 views
Answers (1)
1
Private answer

Navigate to [UFT Install folder]CodeSamplesPlus.

In this folder you'll find a file named HighlightObject.vbs (and several other code samples for various things). Using some modifications to the code in this file, you can choose whatever color (amongst other line options) that you want. Here's sample code that I made to do this. Changing the RGB values (see inline comments) will allow you to pick any RGB combination you like.

'Original UFT highlight function using Orasi.com
Browser(''Orasi Software, Inc'').Page(''Orasi Software, Inc'').Image(''Orasi'').Highlight

' Declare some necessary APIs
Extern.Declare micHwnd, ''GetDesktopWindow'', ''User32.DLL'', ''GetDesktopWindow''
Extern.Declare micULong, ''GetWindowDC'', ''User32.DLL'', ''GetWindowDC'', micHwnd
Extern.Declare micInteger, ''ReleaseDC'', ''User32.DLL'', ''ReleaseDC'', micHwnd, micULong
Extern.Declare micULong, ''CreatePen'', ''Gdi32.DLL'', ''CreatePen'', micInteger, micInteger, micDword
Extern.Declare micInteger, ''SetROP2'', ''Gdi32.DLL'', ''SetROP2'', micULong, micInteger
Extern.Declare micULong, ''SelectObject'', ''Gdi32.DLL'', ''SelectObject'', micULong, micULong
Extern.Declare micULong, ''DeleteObject'', ''Gdi32.DLL'', ''DeleteObject'', micULong
Extern.Declare micULong, ''GetStockObject'', ''Gdi32.DLL'', ''GetStockObject'', micInteger
Extern.Declare micULong, ''Rectangle'', ''Gdi32.DLL'', ''Rectangle'', micULong, micInteger, micInteger, micInteger, micInteger

'Set values of the object location
X = Browser(''Orasi Software, Inc'').Page(''Orasi Software, Inc'').Image(''Orasi'').GetROProperty(''abs_x'')
Y = Browser(''Orasi Software, Inc'').Page(''Orasi Software, Inc'').Image(''Orasi'').GetROProperty(''abs_y'')
H = Browser(''Orasi Software, Inc'').Page(''Orasi Software, Inc'').Image(''Orasi'').GetROProperty(''height'')
W = Browser(''Orasi Software, Inc'').Page(''Orasi Software, Inc'').Image(''Orasi'').GetROProperty(''width'')

'call the function
HighlightRect X,Y, W, H, 1

Function HighlightRect (X, Y, W, H, Times)

' Get the Desktop DC
hDC = Extern.GetWindowDC (Extern.GetDesktopWindow)
' Create a three pixels wide Pen
hPen = Extern.CreatePen (6, 3, RGB(102, 0, 255)) 'By setting RGB values can determine color (refer to http://www.w3schools.com/html/html_colors.asp)
Extern.SetROP2 hDC, 5 ' Replace this number with values from below description
Extern.SelectObject hDC, hPen
' Use an empty fill
Extern.SelectObject hDC, Extern.GetStockObject (5) ' NULL_BRUSH

' Do the Highlight
For i = 0 to Times * 2 + 1
Extern.Rectangle hDC, X, Y, X + W, Y + H
wait 0, 50
Next

' CleanUp
Extern.ReleaseDC Extern.GetDesktopWindow, hDC
Extern.DeleteObject hPen

End Function

'ValueDescription
'R2_BLACKPixel is always 0.
'R2_COPYPENPixel is the pen color.
'R2_MASKNOTPENPixel is a combination of the colors common to both the screen and the inverse of the pen.
'R2_MASKPENPixel is a combination of the colors common to both the pen and the screen.
'R2_MASKPENNOTPixel is a combination of the colors common to both the pen and the inverse of the screen.
'R2_MERGENOTPENPixel is a combination of the screen color and the inverse of the pen color.
'R2_MERGEPENPixel is a combination of the pen color and the screen color.
'R2_MERGEPENNOTPixel is a combination of the pen color and the inverse of the screen color.
'R2_NOPPixel remains unchanged.
'R2_NOTPixel is the inverse of the screen color.
'R2_NOTCOPYPENPixel is the inverse of the pen color.
'R2_NOTMASKPENPixel is the inverse of the R2_MASKPEN color.
'R2_NOTMERGEPENPixel is the inverse of the R2_MERGEPEN color.
'R2_NOTXORPENPixel is the inverse of the R2_XORPEN color.
'R2_WHITEPixel is always 1.
'R2_XORPENPixel is a combination of the colors in the pen and in the screen, but not in both.

Marked as spam
Posted by (Questions: 16, Answers: 807)
Answered on April 22, 2015 5:40 pm
0
That's cool and it works really well.
( at April 22, 2015 5:42 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top