Because I've been passionate about control colors, does this work more stable for you?
Code: Select all
#NoEnv
BackColor := 0xFFFF00
EditControls := {}
Gui Add, Edit, x183 y57 w205 h51 hwndHED, Edit 1
SetFocusedBkColor(HED, BackColor)
Gui Add, Edit, x184 y128 w205 h51 hwndHED, Edit 2
SetFocusedBkColor(HED, BackColor)
Gui Add, Edit, x185 y199 w205 h51 hwndHED, Edit 3
SetFocusedBkColor(HED, BackColor)
OnMessage(0x0133, "SetFocusedBkColor") ; WM_CTLCOLOREDIT
Gui Show, w547 h338, Window
Return
GuiClose:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
SetFocusedBkColor(W, L := "", M := "", H := "") {
Static Controls := {}
If (M && H) { ; system call: W = HDC, L = HWND
If Controls.HasKey(L) {
If (L = DllCall("GetFocus", "UPtr")) {
Controls[L, "Invalidated"] := False
DllCall("SetBkColor", "Ptr", W, "UInt", Controls[L, "Color"])
Return Controls[L, "Brush"]
}
Else If !Controls[L, "Invalidated"] {
Controls[L, "Invalidated"] := True
DllCall("InvalidateRect", "Ptr", L, "Ptr", 0, "UInt", 1)
}
}
}
Else { ; setup call: W = HWND, L = color
If DllCall("IsWindow", "Ptr", W) {
If Controls.HasKey(W) {
DllCall("DeleteObject", "Ptr", Controls[W, "Brush"])
Controls.Delete(W)
}
If (L <> "") && ((EditColor := SwapRB(L)) <> "") {
Controls[W, "Color"] := EditColor
Controls[W, "Brush"] := DllCall("CreateSolidBrush", "UInt", EditColor, "Uptr")
Controls[W, "Invalidated"] := True
}
DllCall("RedrawWindow", "Ptr", W, "Ptr", 0, "Ptr", 0, "UInt", 0x0405, "UInt")
}
}
}
; ----------------------------------------------------------------------------------------------------------------------
SwapRB(Color) { ; converts RGB to BGR and vice versa
Return ((Color & 0xFF0000) >> 16) | (Color & 0x00FF00) | ((Color & 0x0000FF) << 16)
}
Edit: Slight code changes.