#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $WINDOW_TO_QUERY, $___RGBTC, $___RGBBGC
GUIRegisterMsg($WM_CTLCOLORSTATIC, "MY_CTLCOLOR")
GUIRegisterMsg($WM_CTLCOLOREDIT, "MY_CTLCOLOR")
GUIRegisterMsg($WM_CTLCOLORBTN, "MY_CTLCOLOR")
$hGui = GUICreate('Test', 200, 200)
GUISetBkColor(0xABCDEF)
$hButton = GUICtrlCreateButton("change", 20, 160, 40, 20)
$hButton_1 = GUICtrlCreateButton("msg", 120, 160, 40, 20)
$Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x0000FF)
GUISetState()
$Z = 1
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $hButton
;$color=0xABCDEF
If $Z = 1 Then
GUICtrlSetBkColor($Input, 0xABCDEF)
$Z = 0
Else
GUICtrlSetBkColor($Input, 0xADEFAC)
$Z = 1
EndIf
Case $msg = $hButton_1
MsgBox(0, 'Colours in RGB format', 'Text colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input, 1), 6) & @CRLF & _
'BackGnd colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input), 6) & @CRLF & _
'BackGnd colour GUI = : 0x' & Hex(_WinAPI_GetBkColor($hGui), 6) & @CRLF)
EndSelect
WEnd
; $BGC_TC = 0 for background colour, $BGC_TC <> 0 for text colour
Func _WinAPI_GetTextColor($hWnd, $BGC_TC = 0)
; Prog@ndy
Global $___RGBTC = -1, $___RGBBGC = -1
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
$WINDOW_TO_QUERY = $hWnd
_WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INVALIDATE + $RDW_UPDATENOW)
Do
Sleep(10)
Until $___RGBTC <> -1 And $___RGBBGC <> -1
If $BGC_TC = 0 Then
Return $___RGBBGC
Else
Return $___RGBTC
EndIf
EndFunc ;==>_WinAPI_GetTextColor
Func MY_CTLCOLOR($hWnd, $uMsg, $wParam, $lParam)
; Prog@ndy
If $lParam = $WINDOW_TO_QUERY Then
Local $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'ptr', $wParam)
If Not @error Then
Global $___RGBTC = "0x" & StringRegExpReplace(Hex($RGB[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1")
Else
Global $___RGBTC = -2
EndIf
Local $___RGBBGC = DllCall('gdi32.dll', 'int', 'GetBkColor', 'ptr', $wParam)
If Not @error Then
Global $___RGBBGC = "0x" & StringRegExpReplace(Hex($___RGBBGC[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1")
Else
Global $___RGBBGC = -2
EndIf
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc ;==>MY_CTLCOLOR
; Get background colour of GUI window, NOT a control.
Func _WinAPI_GetBkColor($hWnd)
; Not Prog@ndy
Local $aResult, $hDC, $Res
If Not IsHWnd($hWnd) Then $hWnd = ControlGetHandle("", "", $hWnd)
$hDC = _WinAPI_GetDC($hWnd)
$aResult = DllCall("GDI32.dll", "int", "GetBkColor", "hwnd", $hDC)
ConsoleWrite("Hex($aResult[0], 6) = " & Hex($aResult[0], 6) & @CRLF)
$Res = "0x" & StringRegExpReplace(Hex($aResult[0], 6), "(.{2})(.{2})(.{2})", "\3\2\1")
_WinAPI_ReleaseDC($hWnd, $hDC)
Return $Res
EndFunc ;==>_WinAPI_GetBkColor