Hmm... Nobody with the knowledge to help me has read this thread yet?
Anyway, I've been experimenting around with variations to see if I can get this background/forground text color change script to process more than one line of text.
First, I tried to have the code called in a subroutine:
Code:
Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color
Gosub ColorMe
Gui, Add, Text, HwndMyTextHwnd, and a custom foreground color.
Gosub ColorMe
Gui Show
return
ColorMe:
Gui +LastFound
GuiHwnd := WinExist()
TextBackgroundColor := 0xFFFFFF ; A custom color in BGR format.
TextForegroundColor := 0x0000FF ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)
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.
return
WindowProc(hwnd, uMsg, wParam, lParam)
{
Critical
global TextBackgroundColor, TextBackgroundBrush, WindowProcOld, TextForegroundColor
if (uMsg = 0x138 && lParam = A_EventInfo) ; 0x138 is WM_CTLCOLORSTATIC.
{
DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
DllCall("SetTextColor", UInt, wParam, UInt, TextForegroundColor)
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)
}
GuiClose:
ExitApp
That was another failure. It still locked up.
Then I tried a variation where part of the code was rewritten so it was not an exact duplicate. (Changed the variable and fuction names slightly.)
Code:
TextBackgroundColor := 0xFFBBBB ; A custom color in BGR format.
TextForegroundColor := 0x0000FF ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)
Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color
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, Add, Text, HwndAddedTextHwnd, and a custom foreground color.
Gui +LastFound
GuiHwnd_more := WinExist()
WindowProcNew_more := RegisterCallback("WindowProc", "" ; Specifies "" to avoid fast-mode for subclassing.
, 4, AddedTextHwnd) ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd_more, Int, -4 ; -4 is GWL_WNDPROC
, Int, WindowProcNew_more, UInt) ; Return value must be set to UInt vs. Int.
Gui Show
return
WindowProc(hwnd, uMsg, wParam, lParam)
{
Critical
global TextBackgroundColor, TextBackgroundBrush, WindowProcOld, TextForegroundColor
if (uMsg = 0x138 && lParam = A_EventInfo) ; 0x138 is WM_CTLCOLORSTATIC.
{
DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
DllCall("SetTextColor", UInt, wParam, UInt, TextForegroundColor)
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)
}
GuiClose:
ExitApp
Nope. Another failure, another lock-up.
I'm running out of ideas here. And I
really wanted to finish my project...