Advertisement
sashaatx

Untitled

Jul 24th, 2023
3,999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; http://www.autohotkey.com/board/topic/104539-controlcol-set-background-and-text-color-gui-controls/
  2.  
  3. ControlColor(Control, Window, bc := "", tc := "", Redraw := 1) {
  4.     a := {}
  5.     a["c"]  := Control
  6.     a["g"]  := Window
  7.     a["bc"] := (bc = "") ? "" : (((bc & 255) << 16) + (((bc >> 8) & 255) << 8) + (bc >> 16))
  8.     a["tc"] := (tc = "") ? "" : (((tc & 255) << 16) + (((tc >> 8) & 255) << 8) + (tc >> 16))
  9.     CC_WindowProc("Set", a, "", "")
  10.     If (Redraw) {
  11.         WinSet Redraw,, ahk_id %Control%
  12.     }
  13. }
  14.  
  15. CC_WindowProc(hWnd, uMsg, wParam, lParam) {
  16.     Static Win := {}
  17.  
  18.     If uMsg Between 0x132 And 0x138
  19.     If (Win[hWnd].HasKey(lParam)) {
  20.         If (tc := Win[hWnd, lParam, "tc"]) {
  21.             DllCall("gdi32.dll\SetTextColor", "Ptr", wParam, "UInt", tc)
  22.         }
  23.         If (bc := Win[hWnd, lParam, "bc"]) {
  24.             DllCall("gdi32.dll\SetBkColor",   "Ptr", wParam, "UInt", bc)
  25.         }
  26.         Return Win[hWnd, lParam, "Brush"] ; Return the HBRUSH to notify the OS that we altered the HDC.
  27.     }
  28.  
  29.     If (hWnd = "Set") {
  30.         a := uMsg
  31.         Win[a.g, a.c] := a
  32.         If (Win[a.g, a.c, "tc"] == "") And (Win[a.g, a.c, "bc"] == "")
  33.             Win[a.g].Remove(a.c, "")
  34.         If Not Win[a.g, "WindowProcOld"]
  35.             Win[a.g,"WindowProcOld"] := DllCall("SetWindowLong" . (A_PtrSize == 8 ? "Ptr" : "")
  36.             , "Ptr", a.g, "Int", -4, "Ptr", RegisterCallback("CC_WindowProc", "", 4), "UPtr")
  37.         If Win[a.g, a.c, "Brush"]
  38.             DllCall("gdi32.dll\DeleteObject", "Ptr", Brush)
  39.         If (Win[a.g, a.c, "bc"] != "")
  40.             Win[a.g, a.c, "Brush"] := DllCall("gdi32.dll\CreateSolidBrush", "UInt", a.bc, "UPtr")
  41.         Return
  42.     }
  43.     Return DllCall("CallWindowProc", "Ptr", Win[hWnd, "WindowProcOld"], "Ptr", hWnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam, "Ptr")
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement