Jump to content

Text Color


 Share

Recommended Posts

Hi All,

I have some static text fields and I would like to check their color. I tried this approach, but there seems to be a loop-hole somewhere. Works for white but not for the color amber :( Any tips on how I could improve this? I was hoping to use PixelGetColor, but it didn't work for this use case.

$object ="Static1"
$color = 0xFFB400 ;Color retrieved using the spy tool


$txtPos = ControlGetPos ( "<title>", "", $object ) 
    if not @error = 1 then
        $searchPix =  PixelSearch ($txtPos[0] , $txtPos[1] , $txtPos[2] , $txtPos[3], $color, 10) ;10 shades tolerance
        if @error = 1 Then
            ;Hex($color) & " not present in the object " & $object & " - "
            return false;
        Else
            return true;
        EndIf
    Else
        ;Unable to find object: " & $object
    endif

Appreciate your time!

Edited by tester123
Link to comment
Share on other sites

Thanks FF, but looping with a PixelGetColor also returns 0 - perhaps, i'm doing something terribly wrong with that function.

But I'm curious as to why PixelSearch is not working in this case:

I'm trying to debug - Here's what ControlGetPos returns

    $array[0] = X position
    $array[1] = Y position
    $array[2] = Width
    $array[3] = Height

PixelSearch ( left, top, right, bottom, color [, shade-variation [, step [, hwnd]]] )

$txtPos = ControlGetPos ( "<title>", "", $object ) 

<<Value returned is X:357, Y:535, Width: 115, Height:22 >>

$searchPix =  PixelSearch ($txtPos[0] , $txtPos[1] , $txtPos[2] , $txtPos[3], $color, 10)  incorrect?

<<Not able to find color>>

(AutoIT formatted code in the first post)

I tried with Opt("PixelCoordMode", 0) 1 and 2 - No difference..

I substituted with some random values which would cover the entire screen

$searchPix =  PixelSearch (0 , 0 , 100 , 900, $color, 10) This works fine and apparently the color was found at the position 80, 747 which for some reason is way off from where $txtPos location is.

MsgBox(0, "X and Y are:", $searchPix[0] & "," & $searchPix[1]) --> 80, 747

80,747 and 357,535,115,22 - > Am I missing something?

Any suggestions?

Edited by tester123
Link to comment
Share on other sites

Something like this:

#include <WinAPI.au3>
 
Global Const $SM_CYCAPTION = 4, $SM_CXDLGFRAME = 7
 
Local Const $iCaptionHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Local Const $iBorderSize = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
 
; your code here
 
ConsoleWrite("Color: " & Hex(ControlGetColor("<title>", "Static1"), 6) & @CrLf)
 
Func ControlGetColor($hWnd, $vControlID, $iBkColor = 0xF0F0F0)
    Local $aCtrlPos = ControlGetPos($hWnd, "", $vControlID)
    Local $aWgp = WinGetPos($hWnd)
 
    For $iX = $aWgp[0] + $aCtrlPos[0] To $aWgp[0] + $aCtrlPos[0] + $aCtrlPos[2]
        For $iY = $aWgp[1] + $aCtrlPos[1] To $aWgp[1] + $aCtrlPos[1] + $aCtrlPos[3]
            $iColor = PixelGetColor($iX + $iBorderSize, $iY + $iBorderSize + $iCaptionHeight)
            If $iColor <> $iBkColor Then Return $iColor
        Next
    Next
 
    Return -1
EndFunc

But it's not accurate at all, if you know the possible colors then it would be better to put them in an array and if a color from this array is found then return the color.

Br, FireFox.

Link to comment
Share on other sites

Hey thank you very much for taking the time to write down code! *Like*

Unfortunately, it takes a whole lotta time even with step included and like you mentioned it wasnt being accurate :( I guess I'll just have to use the Pixel Search approach with the entire window. *sigh*

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...