its not perfect yet but seems to work on a wider variety of windows.


#NoEnv ; Example for colored backgrounds for multiple controls ; based upon the RCB example from helpfile ; Description: It works with a redirection of the CallWindowProc to a UserDefinedFunction ; Within the script. Right after execution the Call will be directed to the ; origin address. ; HTML Colors in BGR-format Black = 0x000000 Green = 0x008000 Silver = 0xC0C0C0 Lime = 0x00FF00 Gray = 0x808080 Olive = 0x800080 White = 0xFFFFFF Yellow = 0x00FFFF Maroon = 0x000080 Navy = 0x800000 Red = 0x0000FF Blue = 0xFF0000 Purple = 0x800080 Teal = 0x808000 Fuchsia = 0xFF00FF Aqua = 0xFFFF00 Gui, Margin, 10, 10 Gui, Font, s12 Gui, Color, Black Gui, Add, Text, vTXT1 HwndTX1ID w300, A little Text`nwith colored Background Control_Colors("TXT1", "Set", Teal, White) Gui, Add, CheckBox, HwndCB1ID wp vCB1 gCB1Clicked, A Checkbox Control_Colors("CB1", "Set", Silver) Gui, Add, Radio, HwndRB1ID xp y+0 wp vRB1 gRB1Clicked, Radiobutton used as Checkbox RB1 := False Control_Colors("RB1", "Set", Silver) Gui, Add, Edit, vROED1 HwndED1ID ReadOnly wp, This is a Readonly Edit! Control_Colors("ROED1", "Set", Red, Yellow) Gui, Add, Text, vDTXT1 HwndTX2ID Disabled wp, This Text is disabled. Control_Colors("DTXT1", "Set", Maroon, Black) Gui, Add, Edit, vED1 HwndED2ID r2 wp, A normal editfield Control_Colors("ED1", "Set", Navy, White) Gui, Add, Button, vBTChange gBTChange wp, Change that Colors! Gui, +LastFound GuiID := WinExist() Control_Colors(GuiID, "RCB", 0, 0) Gui, Show, , Colors Return GuiEscape: GuiClose: ExitApp BTChange: Control_Colors(TX1ID, "Set", Red, Teal) Control_Colors(ED1ID, "Set", Maroon, Yellow) Control_Colors(TX2ID, "Set", Aqua, White) Control_Colors(ED2ID, "Set", Silver, Navy) Gui, +LastFound WinSet, Redraw GuiControl, Hide, BTChange Gui, Show, AutoSize Return CB1Clicked: GuiControlGet, CB1 Control_Colors(CB1ID, "Set", (CB1 ? Yellow : Silver)) WinSet, Redraw, , ahk_id %CB1ID% Return RB1Clicked: RB1 ^= True Control_Colors(RB1ID, "Set", (RB1 ? Green : Silver)) WinSet, Redraw, , ahk_id %RB1ID% GuiControl, , RB1, %RB1% Return Control_Colors(Hwnd, Msg, wParam, lParam = 0) { Critical If !(Hwnd+0) { GuiControlGet, nHwnd, Hwnd, %Hwnd% Hwnd := nhwnd } Static OldWinProc := "" ; origin Windowprocedure Static NewWinProc := "" ; new Windowprocedure Static SetValue := "Set" ; take over Values Static Register := "RCB" ; RegisterCallBack Static ValueList := "" ; Values ; Aufruf als Fensterprozedur? If (A_EventInfo <> NewWinProc) { If (Msg = SetValue) { If (RegExMatch(ValueList, "m)^" . (Hwnd +0) . "\|")) { ValueList := RegExReplace(ValueList , "m)^" . (Hwnd + 0) . "\|.*$" , (Hwnd + 0) . "|" . (wParam + 0) . "|" . (lParam + 0)) } Else { ValueList .= (Hwnd + 0) . "|" . (wParam + 0) . "|" . (lParam + 0) . "`r`n" } Return } If (Msg = Register) { If (NewWinProc = "") { NewWinProc := RegisterCallback("Control_Colors","",4) OldWinProc := DllCall("SetWindowLong" , UInt, Hwnd , Int, -4 , Int, NewWinProc , UInt) } Return } Return } ; 0x0133 : WM_CTLCOLOREDIT ; 0x0138 : WM_CTLCOLORSTATIC If (Msg = 0x0133 Or Msg = 0x0135 Or Msg = 0x0138) { If (RegExMatch(ValueList, "m)^" . (lParam + 0) . "\|(?P<BG>\d+)\|(?P<TX>\d+)$" , C)) { DllCall("SetTextColor", UInt, wParam, UInt, CTX) DllCall("SetBkColor", UInt, wParam, UInt, CBG) Return, DllCall("CreateSolidBrush", UInt, CBG) } } Return DllCall("CallWindowProcA" , UInt, OldWinProc , UInt, Hwnd , UInt, Msg , UInt, wParam , UInt, lParam) }
i just expanded the example from helpfile about RCB / denick got curious and expanded the function to a more mature function (which i slightly modified to work bit more generic)
originally published here: http://de.autohotkey...opic.php?t=2570
greets
DerRaphael