Alundaio Guest
|
Posted: Thu Mar 18, 2010 11:09 pm Post subject: Change Background Color of Edit Control |
|
|
How to change the background color on specific Edit controls? I thought there was an easy way to do it, like using Gui, Color. But that doesn't seem to work.
I also tried using an altered version of the Registry_Callback() example. But I do not know how pass other params (x,y,w,h). Also it will only work on just one control.
| Code: | ; Example: The following is a working script that demonstrates how to subclass a GUI window by
; redirecting its WindowProc to a new WindowProc in the script. In this case, the background
; color of a text control is changed to a custom color.
TextBackgroundColor := 0xFFBBBB ; 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 Show
return
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)
}
GuiClose:
ExitApp |
|
|