Note: Requires WinAPIEx.au3 to use GUICtrlGetBkColor().
To get the Hex value e.g. 00FF00 then use this little conversion >>
Function:
; #FUNCTION# ==================================================================================================================== ; Name ..........: GUICtrlGetBkColor ; Description ...: Retrieves the RGB value of the control background. ; Syntax ........: GUICtrlGetBkColor($hWnd) ; Parameters ....: $hWnd - Control ID/Handle to the control ; Return values .: Success - RGB value ; Failure - 0 ; Author ........: guinness ; Remarks .......: WinAPIEx is required. ; Example .......: Yes ; =============================================================================================================================== Func GUICtrlGetBkColor($hWnd) If IsHWnd($hWnd) = 0 Then $hWnd = GUICtrlGetHandle($hWnd) EndIf Local $hDC = _WinAPI_GetDC($hWnd) Local $iColor = _WinAPI_GetPixel($hDC, 0, 0) _WinAPI_ReleaseDC($hWnd, $hDC) Return $iColor EndFunc ;==>GUICtrlGetBkColor
Example use of Function:
#include <WinAPIEx.au3> ; Required for _WinAPI_GetPixel() #include 'GUICtrlGetBkColor.au3' Example() Func Example() Local $aColor[6] = [5, 0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random Color Array. Local $iColor = 0 Local $hGUI = GUICreate('GUICtrlGetBkColor() Example', 500, 350) Local $iLabel = GUICtrlCreateLabel('', 10, 10, 480, 330) GUISetState(@SW_SHOW, $hGUI) For $i = 1 To $aColor[0] GUICtrlSetBkColor($iLabel, $aColor[$i]) Sleep(20) $iColor = GUICtrlGetBkColor($iLabel) ; Pass the Label ID to the Function. MsgBox(4096, '', 'Background Color: ' & _ConvertToHexFormat($aColor[$i]) & @CRLF & _ 'GUICtrlGetBkColor() Hex Format: ' & _ConvertToHexFormat($iColor) & @CRLF & _ 'GUICtrlGetBkColor() Returned: ' & $iColor, 0, $hGUI) Next GUIDelete($hGUI) EndFunc ;==>Example Func _ConvertToHexFormat($bColor) Return Hex($bColor, 6) EndFunc ;==>_ConvertToHexFormat
Additional thanks to Yashied for pointing out the obvious in this forum message about _WinAPI_GetPixel() and the hint about returning a RGB number
Edited by guinness, 17 October 2012 - 08:09 PM.





