Sign in to follow this  
Followers 0
XTensionX

Get colour

19 posts in this topic

Hi, im wondering if there is a way to get the colour of a label in my GUI.

I've looked around but there dont seem to be any.

Thanks

Share this post


Link to post
Share on other sites



Thanks PsaltyDS :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Thanks guys :)

But I wanted to get the colour of the text and not the background.

How can I change the function to make it get the text colour in the Label? ;)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Did you set the colour of the text? And you didn't mention this in the OP!

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Did you set the colour of the text? And you didn't mention this in the OP!

My bad =/ yeah I did,

I have used the example of GUICtrGetBkColor() from your example script to test it out:

#include <WinAPIEx.au3> ; Reguired for _WinAPI_GetPixel()

_Main()

Func _Main()
    Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array.
    Local $hGUI, $iColor, $iLabel

    $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350)
    $iLabel = GUICtrlCreateLabel("wt", 0, 0, 500, 350)
    GUICtrlSetColor(-1, 0x000000)
    GUISetState(@SW_SHOW)

    $iColor = GUICtrlGetBkColor($iLabel)
MsgBox(0, "The Hex value is...", _ConvertToHexFormat($iColor))
    Exit
EndFunc   ;==>_Main



Func _ConvertToHexFormat($iColor)
    Return Hex($iColor, 6)
EndFunc   ;==>_ConvertToHexForma


Func GUICtrlGetBkColor($iControlID)
    Local $bGetBkColor, $hDC, $hHandle
    $hHandle = GUICtrlGetHandle($iControlID)
    $hDC = _WinAPI_GetDC($hHandle)
    $bGetBkColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hHandle, $hDC)
    Return $bGetBkColor
EndFunc   ;==>GUICtrlGetBkColor

Share this post


Link to post
Share on other sites

I could be wrong, but I don't think what you're asking is possible.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hmm... seems like this should have worked, but it doesn't:

#include <WinAPIEx.au3>

_Main()

Func _Main()
    Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array.
    Local $hGUI, $iColor, $aLabel[6] = [5]

    $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350)

    For $n = 1 To 5
        $aLabel[$n] = GUICtrlCreateLabel("Label " & $n, 10, 10 + ($n * 30), 480, 20)
        GUICtrlSetColor($aLabel[$n], $aColor_Array[$n])
    Next

    GUISetState(@SW_SHOW)

    For $n = 1 To 5
        $hHandle = GUICtrlGetHandle($aLabel[$n])
        $hDC = _WinAPI_GetDC($hHandle)
        $iColor = _WinAPI_GetTextColor($hDC)
        $iErrSav = @error
        ConsoleWrite("$aColor_Array[" & $n & "] = 0x" & Hex($aColor_Array[$n]) & "; $aLabel[" & $n & "] = " & $aLabel[$n] & _
                "; $hHandle = " & $hHandle & "; $hDC = " & $hDC & "; $iColor = 0x" & Hex($iColor) & "; @error = " & $iErrSav & @LF)
        _WinAPI_ReleaseDC($hHandle, $hDC)
    Next

    Do
    Until GUIGetMsg() = -3
EndFunc   ;==>_Main

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This also should work, but nope... :)

#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
Global $hGUI, $iColor, $aLabel[6] = [5]
_Main()
Func _Main()
    Local $aColor_Array[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array.
    $hGUI = GUICreate("GUICtrlGetBkColor() Example", 500, 350)
    GUIRegisterMsg($WM_CTLCOLORSTATIC, "WM_CTLCOLORSTATIC")
    For $n = 1 To 5
        $aLabel[$n] = GUICtrlCreateLabel("Label " & $n, 10, 10 + ($n * 30), 480, 20)
        GUICtrlSetColor($aLabel[$n], $aColor_Array[$n])
    Next
    GUICtrlCreateButton("", 150, 200, 100, 60)
    GUISetState(@SW_SHOW)
    Do
    Until GUIGetMsg() = -3
EndFunc   ;==>_Main
Func WM_CTLCOLORSTATIC($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_SetTextColor($wParam, 0xff0000) ; All the labels must have red text..
    _WinAPI_SetBkColor($wParam, 0x000000) ; All the labels must have black background..
;   _winapi_getbkcolor($wParam)
    _WinAPI_SetBkMode($wParam, $OPAQUE) ; All the labels must not have transparent Bk..
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_CTLCOLORSTATIC
Edited by monoscout999

Share this post


Link to post
Share on other sites

Thanks for the replies guys

Guess this isnt possible :/

Share this post


Link to post
Share on other sites

XTensionX,

Guess this isnt possible

Guessed wrong! ;)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFF00)

GUISetState()

$iBackColour = GUICtrlGetBkColorEx($hLabel)
ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF)

$iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour)
If @error Then
    ConsoleWrite("No text found" & @CRLF)
Else
    ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF)
EndIf

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol)

    Local $tPoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why

    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            If PixelGetColor($iX, $iY) <> $iBkCol Then
                ; Assume that it is text colour
                Return PixelGetColor($iX, $iY)
            EndIf
        Next
    Next

    ; Text colour not found, so return error
    Return SetError(1, 0, 0)

EndFunc

Func GUICtrlGetBkColorEx($iControlID)
    Local $aResult, $bGetBkColor, $hDC, $hHandle
    $hHandle = GUICtrlGetHandle($iControlID)
    $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    $hDC = $aResult[0]
    $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0)
    If @error Or ($aResult[0] = 0xFFFFFFFF) Then
        Return SetError(@error, @extended, 0)
    EndIf
    $bGetBkColor = $aResult[0]
    $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16))
EndFunc   ;==>GUICtrlGetBkColorEx

Not pretty but it works. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Not working for me Melba. :)

The text color output is wrong and changes every time I run the script.

Edit: Seems like the aero fading effect of Windows 7 caused the problem.

Passing WinWait($hGUI) after GUISetState() fixes it.

Great work Melba!

Edited by Info

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Not pretty but it works. ;)

Hmm... not for me. You are setting background to 0xFFFF00 (yellow), and text to 0xFF0000. But this is what I get:
>Running:(3.3.7.10):C:\Program Files\AutoIt3\Beta\autoit3.exe "C:\Temp\Test1.au3"    
BackColor: 0xFFFF00
TextColor: 0xE5ECF3
Moreover, I get a different color every time, i.e. 0xB0B5F6, 0xF4F0F9, etc.

Same problem in either Prod or Beta.

Win7Pro x32.

;)

Edit: Added some debug to it, and now I get the same wrong answer every time. Weird. Debug version:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFF00)

GUISetState()

$iBackColour = GUICtrlGetBkColorEx($hLabel)
ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF)

$iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour)
If @error Then
    ConsoleWrite("No text found" & @CRLF)
Else
    ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF)
EndIf

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

Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol)
    Local $tPoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)

    ; Convert to screen coords
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why
    ConsoleWrite("Debug:  X = " & $aPos[0] & "; Y = " & $aPos[1] & "; W = " & $aPos[2] & "; H = " & $aPos[3] & @LF)

    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            $iFindColor = PixelGetColor($iX, $iY)
            ConsoleWrite("Debug:  $iX = " & $iX & "; $iY = " & $iY & "; $iFindColor = 0x" & Hex($iFindColor, 6) & @LF)

            If $iFindColor <> $iBkCol Then
                ; Assume that it is text colour
                MouseMove($iX, $iY) ; Point to where it was found
                Return $iFindColor
            EndIf
        Next
    Next

    ; Text colour not found, so return error
    Return SetError(1, 0, 0)
EndFunc   ;==>_GUICtrlGetTextColor

Func GUICtrlGetBkColorEx($iControlID)
    Local $aResult, $bGetBkColor, $hDC, $hHandle
    $hHandle = GUICtrlGetHandle($iControlID)
    $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    $hDC = $aResult[0]
    $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0)
    If @error Or ($aResult[0] = 0xFFFFFFFF) Then
        Return SetError(@error, @extended, 0)
    EndIf
    $bGetBkColor = $aResult[0]
    $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16))
EndFunc   ;==>GUICtrlGetBkColorEx

Result:

>Running:(3.3.7.10):C:\Program Files\AutoIt3\Beta\autoit3.exe "C:\Temp\Test1.au3"    
BackColor: 0xFFFF00
Debug:  X = 445; Y = 137; W = 100; H = 20
Debug:  $iX = 445; $iY = 137; $iFindColor = 0xF0F4F9
TextColor: 0xF0F4F9

I don't get it. The mouse pointer goes to the right place, so it looks like PixelGetColor() is actually failing.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Arrrgh! Just put a Sleep() after GuiSetState() and it works! The pixel checking was happening before the GUI was displayed. This could be variable based on Windows effects like fading in new windows.

Sheesh! And could have saved myself all the trouble by reading Info's post earlier!

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You did a good job melba23... but despite that you find a solution, i still have the bitter sensation that the _winapi_gettextcolor() function should be work, but it doesn´t, even with Static classes outside autoit.

Share this post


Link to post
Share on other sites

Well I never! :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

XTensionX,

Guessed wrong! ;)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Test", 10, 10, 100, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xFFFF00)

GUISetState()

$iBackColour = GUICtrlGetBkColorEx($hLabel)
ConsoleWrite("BackColor: 0x" & Hex($iBackColour, 6) & @CRLF)

$iTextColour = _GUICtrlGetTextColor($hGUI, $hLabel, $iBackColour)
If @error Then
    ConsoleWrite("No text found" & @CRLF)
Else
    ConsoleWrite("TextColor: 0x" & Hex($iTextColour, 6) & @CRLF)
EndIf

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _GUICtrlGetTextColor($hWnd, $hControl, $iBkCol)

    Local $tPoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tPoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tPoint, "Y") + 1 ; I have no idea why

    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            If PixelGetColor($iX, $iY) <> $iBkCol Then
                ; Assume that it is text colour
                Return PixelGetColor($iX, $iY)
            EndIf
        Next
    Next

    ; Text colour not found, so return error
    Return SetError(1, 0, 0)

EndFunc

Func GUICtrlGetBkColorEx($iControlID)
    Local $aResult, $bGetBkColor, $hDC, $hHandle
    $hHandle = GUICtrlGetHandle($iControlID)
    $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hHandle)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    $hDC = $aResult[0]
    $aResult = DllCall("gdi32.dll", "dword", "GetPixel", "hwnd", $hDC, "int", 0, "int", 0)
    If @error Or ($aResult[0] = 0xFFFFFFFF) Then
        Return SetError(@error, @extended, 0)
    EndIf
    $bGetBkColor = $aResult[0]
    $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hHandle, "handle", $hDC)
    If @error Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return BitOR(BitAND($bGetBkColor, 0x00FF00), BitShift(BitAND($bGetBkColor, 0x0000FF), -16), BitShift(BitAND($bGetBkColor, 0xFF0000), 16))
EndFunc   ;==>GUICtrlGetBkColorEx

Not pretty but it works. :)

M23

Thanks Thanks Melba23 ^^

This is working perfectly ;)

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  
Followers 0