; 帮助文档中RegisterCallback的示例
TextBackgroundColor := 0xFFBBBB ; BGR 格式的自定义颜色.
TextBackgroundBrush := DllCall("CreateSolidBrush", "UInt", TextBackgroundColor)
Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color.
Gui +LastFound
GuiHwnd := WinExist()
; 64 位脚本必须调用 SetWindowLongPtr 代替 SetWindowLong:
SetWindowLong := A_PtrSize=8 ? "SetWindowLongPtr" : "SetWindowLong"
WindowProcNew := RegisterCallback("WindowProc", "" ; 指定 "" 来避免子类化中使用快速模式.
, , MyTextHwnd) ; 在 [v1.1.12+] 中, 可以像这样省略 ParamCount.
WindowProcOld := DllCall(SetWindowLong, "Ptr", GuiHwnd, "Int", -4 ; -4 是 GWL_WNDPROC
, "Ptr", WindowProcNew, "Ptr") ; 返回值必须设置为 Ptr 或 UPtr 而不是 Int.
Gui Show
return
WindowProc(hwnd, uMsg, wParam, lParam)
{
Critical
global TextBackgroundColor, TextBackgroundBrush, WindowProcOld
if (uMsg = 0x0138 && lParam = A_EventInfo) ; 0x0138 为 WM_CTLCOLORSTATIC.
{
DllCall("SetBkColor", "Ptr", wParam, "UInt", TextBackgroundColor)
return TextBackgroundBrush ; 返回 HBRUSH 来通知操作系统我们改变了 HDC.
}
; 否则 (如果上面没有返回), 传递所有的未处理事件到原来的 WindowProc.
return DllCall("CallWindowProc", "Ptr", WindowProcOld, "Ptr", hwnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam)
}
GuiClose:
ExitApp
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)