Jump to content

Get color of a control


Recommended Posts

Hi guys,

I don't have never used all the pixel function so the error maybe is simple. I want to know the color of a control inside the GUI:

#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("My Name", 293, 154, -1, -1)
$Label = GUICtrlCreateLabel("", 100, 56, 28, 28)
GUICtrlSetBkColor(-1, 0x0054E3)
GUISetState(@SW_SHOW)

$aPos = ControlGetPos($hGUI, "", $Label)
ConsoleWrite("Position: " & $aPos[0] & "," & $aPos[1] & @CRLF & "Size: " & $aPos[2] & "," & $aPos[3] & @CR)
$Col = PixelGetColor($aPos[0], $aPos[1], $Form1)
ConsoleWrite("Color: 0x" & Hex($Col, 6) & @CR)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

The output is:

Position: 100,56
Size: 28,28
Color: 0xECE9D8

As you can see, the color don't match 0xECE9D8 vs 0x0054E3

Why?

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Probably the coordinates are different than expected. Try to set AutoItSetOption("GUICoordMode", 0) and try again.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Done, the result is:

Position: 99,55
Size: 28,28
Color: 0xECE9D8

Always different. Thanks

EDIT: Solved with "PixelCoordMode" with 2, thanks UEZ for point me in the right direction :D

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • 2 weeks later...

You can use also _WinAPI_GetSysColor() to get the default color of any specified display element.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can also retrieve the position relative to screen of the control by using WinGetPos and the control handle as parameter :

$hCtrl = GUICtrlGetHandle($Label)
$aPos = WinGetPos( $hCtrl)
ConsoleWrite("Position: " & $aPos[0] & "," & $aPos[1] & @CRLF & "Size: " & $aPos[2] & "," & $aPos[3] & @CR)
$Col = PixelGetColor($aPos[0], $aPos[1], $hGUI)
ConsoleWrite("Color: 0x" & Hex($Col, 6) & @CR)

 

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...