Syed
10 years agoOccasional Contributor
How do you get the background colour of a textbox,cell ,dropdown?
Hi, In My project i have a standalone application whose cell colour changes to green or red depending on the functionality performed please let me know how do we get the background colour of the ...
- 10 years ago
This is a VBScript example. It will return a RGB value of the one pixel at the coordinate of the object that you pass to the function.
Function Return_RGB(objWindowType, nvXcoord, nvYcoord) ****************************************************************************************** '* FUNCTION: Return_RGB(objWindowType As Object, nvXcoord As Long, nvYcoord As Long) '* '* PURPOSE: To return a RGB set of values that is the color of the X, Y coordinate of the Window Object '* '* EXAMPLE: Return_RGB(Sys.Process("MyProcess").VCLObject("frmMain"), 10, 10) Normal Window object '* '* The example returns the RGB color of the pixel at the 10,10 coordinate of the Sys.Process("MyProcess").VCLObject("frmMain") object. '* The return value is a string that would look like >>> 255,26,0 '* The '255' is the Red value. 1st position '* The '26' is the Green value. 2nd position '* The '0' is the Blue value. 3rd position '* '* Last Update: 02-27-2014 - TEB - Converted to TestComplete script. '* 05-01-2009 - TEB - Created '****************************************************************************************** Dim tPOS, dcWindow, nvRGB, svTemp Dim lRed, lGreen, lBlue Set tPOS = POINTAPI Return_RGB = "NO COLOR FOUND" If objWindowType.Exists = True Then ' Move to the X, Y coordinate objWindowType.HoverMouse nvXcoord, nvYcoord ' Get the dc of a specific hwnd - the desktop dcWindow = Win32API.GetWindowDC(0) ' Get the cursor position relative to the screen. tPOS.y = objWindowType.ScreenTop + nvYcoord tPOS.x = objWindowType.ScreenLeft + nvXcoord ' Use GetPixel() with the appropriate DC and location nvRGB = Win32API.GetPixel(dcWindow, tPOS.x, tPOS.y) ' HEX to string svTemp = Right("000000" & Hex(nvRGB), 6) ' Parse out the individual values lRed = CLng("&H" & Right(svTemp, 2)) lGreen = CLng("&H" & Mid(svTemp, 3, 2)) lBlue = CLng("&H" & Left(svTemp, 2)) Return_RGB = CStr(lRed) & "," & CStr(lGreen) & "," & CStr(lBlue) 'Return the RGB values here Else Return_RGB = "NO COLOR FOUND" Log.Warning "Return_RGB - NO COLOR FOUND - Object did not exist - Window to check= " & objWindowType.Name End If End Function Almost forgot.......You will need these functions to define the POINTAPI class Class classPOINTAPI ' Used in Function Return_RGB Public x Public y End Class Function POINTAPI Set POINTAPI = New classPOINTAPI End Function