If you set the Label background colour with GUICtrlSetBkColor() and happen to forget the colour you set it as, then why not try GUICtrlGetBkColor() Function: #include-once
#include <WinAPIGdi.au3>
; #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
; Example .......: Yes
; ===============================================================================================================================
Func GUICtrlGetBkColor($hWnd)
If Not IsHWnd($hWnd) Then
$hWnd = GUICtrlGetHandle($hWnd)
EndIf
Local $hDC = _WinAPI_GetDC($hWnd)
Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
_WinAPI_ReleaseDC($hWnd, $hDC)
Return $iColor
EndFunc ;==>GUICtrlGetBkColorExample use of Function: #include <MsgBoxConstants.au3>
#include 'GUICtrlGetBkColor.au3'
Example()
Func Example()
Local $hGUI = GUICreate('GUICtrlGetBkColor() Example', 500, 350)
Local $iLabel = GUICtrlCreateLabel('', 10, 10, 480, 330)
GUISetState(@SW_SHOW, $hGUI)
Local $aColor = [0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random colour array.
Local $iColor = 0
For $i = 0 To UBound($aColor) - 1
GUICtrlSetBkColor($iLabel, $aColor[$i])
Sleep(20)
$iColor = GUICtrlGetBkColor($iLabel) ; Pass the controldid to the function.
MsgBox($MB_SYSTEMMODAL, '', 'Background Color: ' & _ConvertToHexFormat($aColor[$i]) & @CRLF & _
'GUICtrlGetBkColor() Hex Format: ' & _ConvertToHexFormat($iColor) & @CRLF & _
'GUICtrlGetBkColor() Returned: ' & $iColor, 0, $hGUI)
Next
GUIDelete($hGUI)
EndFunc ;==>Example
Func _ConvertToHexFormat($iColor)
Return Hex($iColor, 6)
EndFunc ;==>_ConvertToHexFormatAdditional thanks to Yashied for pointing out the obvious in this >forum message about _WinAPI_GetPixel() and the hint about returning a RGB number