Thanks! This is almost exactly what I'm looking for.
I do have two slight problems implementing this code into my project, however. First, I have two separate text boxes for which I want to change the background color for. So I'd like to call this function twice.
Secondly, this code changes not only the background color, but it overrides my cRed color specification for the text forground color. And I have no idea how to modify this code to either leave the forground color alone or change it to red.
Code:
#NoTrayIcon
TextBackgroundColor := 0xFFFFFF ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)
Gui +LastFound ; Make the GUI window the last found window for use by the line below.
WinSet, Transparent, 210
Gui, Add, Text, x86 y20 w312 h98 0x6 ,
Gui, Add, GroupBox, x90 y18 w304 h96 ,
Gui, Font, S28 cRed Bold, Arial
Gui, Add, Text, x136 y34 w220 h40 HwndMyTextHwnd, JAVERSION
Gui +LastFound
GuiHwnd := WinExist()
Gui, Font, S18 cRed Bold, Arial
Gui, Add, Text, x104 y71 w280 h30 HwndMyTextHwnd, Java Version Verifier 0.7
Gui +LastFound
GuiHwnd := WinExist()
WindowProcNew := RegisterCallback("WindowProc", "" ; Specifies "" to avoid fast-mode for subclassing.
, 4, MyTextHwnd) ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd, Int, -4 ; -4 is GWL_WNDPROC
, Int, WindowProcNew, UInt) ; Return value must be set to UInt vs. Int.
Gui, Font, S10 cBlack, Arial
Gui, Add, Text, x17 y140 w450 h270 , Some More Text
Gui, Show, w486 h434, Javersion - Java Version Verifier
Return
GuiClose:
ExitApp
WindowProc(hwnd, uMsg, wParam, lParam)
{
Critical
global TextBackgroundColor, TextBackgroundBrush, WindowProcOld
if (uMsg = 0x138 && lParam = A_EventInfo) ; 0x138 is WM_CTLCOLORSTATIC.
{
DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
return TextBackgroundBrush ; Return the HBRUSH to notify the OS that we altered the HDC.
}
; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc.
return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}