Code: Select all
; callback for onMessage(0x0138,"WM_CTLCOLOR")
wm_ctlcolor(wParam,lParam,hwnd){
if(!isObject(ctlColorObj[lParam]))
return
hBrush:=dllCall("Gdi32.dll\CreateSolidBrush","UInt",ctlColorObj[lParam].bg,"UPtr")
if(ctlColorObj[lParam].text)
dllCall("gdi32.dll\SetTextColor","Ptr",wParam,"UInt",ctlColorObj[lParam].text)
dllCall("gdi32.dll\SetBkColor","Ptr",wParam,"UInt",ctlColorObj[lParam].bg)
dllCall("gdi32.dll\SetBkMode","Ptr",wParam,"Int",2)
return hBrush
}
Code: Select all
global ctlColorObj:={}
onMessage(0x0138,"WM_CTLCOLOR")
gui,add,edit,+readonly +hwndchlhwnd r20 w300,Demo text.
ctlColorObj[chlhwnd]:={bg:0xff00ff,text:0xffffff}
gui,show,,Control Color
return
guiClose:
exitApp
F1::
ctlColorObj[chlhwnd]:={bg:0xff00ff,text:0xffffff}
winSet,redraw,,% "ahk_id " . chlhwnd
return
F2::
ctlColorObj[chlhwnd]:={bg:0x00ff00,text:0x000000}
winSet,redraw,,% "ahk_id " . chlhwnd
return
wm_ctlcolor(wParam,lParam,hwnd){
if(!isObject(ctlColorObj[lParam]))
return
hBrush:=dllCall("Gdi32.dll\CreateSolidBrush","UInt",ctlColorObj[lParam].bg,"UPtr")
if(ctlColorObj[lParam].text)
dllCall("gdi32.dll\SetTextColor","Ptr",wParam,"UInt",ctlColorObj[lParam].text)
dllCall("gdi32.dll\SetBkColor","Ptr",wParam,"UInt",ctlColorObj[lParam].bg)
dllCall("gdi32.dll\SetBkMode","Ptr",wParam,"Int",2)
return hBrush
}
Thanks to burque505 and guest3456