Jump to content
Sign in to follow this  
tester123

Text Color

Recommended Posts

tester123

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

Share this post


Link to post
Share on other sites
FireFox

Hi,

From a forum search: 

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
tester123

Thanks FireFox, I forgot to mention earlier that PixelGetColor returns 0 and thats why I used the Pixel Search approach. I tried the method in the link and that returns 0 as well. Any suggestions as to why the above code breaks?

Share this post


Link to post
Share on other sites
FireFox

Hi,

If the background color of the control is always the same, you can iterate through the pixels and find a different color from the background - which will be the color of the label.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
tester123

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

Share this post


Link to post
Share on other sites
FireFox

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.

  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
tester123

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*

Share this post


Link to post
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
Sign in to follow this  

×