Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Change background color of individual controls


  • Please log in to reply
2 replies to this topic
rdwray
  • Members
  • 60 posts
  • Last active: Jul 05 2015 11:26 AM
  • Joined: 14 Feb 2012

This will change the text color of individual controls, but not the background. The first background color changes all control and cannot be modified. If the second control has the focus, the background color does change but reverts back after losing focus. How can individual background colors be set?

; Made this a clear and simple as possible.

global HEDIT_1, HEDIT_2

;BG_COLOR   := 0x995522
;FG_COLOR   := 0xFAFAFA

WM_CTLCOLORMSGBOX = 0x132
WM_CTLCOLOREDIT = 0x133
WM_CTLCOLORLISTBOX = 0x134
WM_CTLCOLORBTN = 0x135
WM_CTLCOLORDLG = 0x136
WM_CTLCOLORSCROLLBAR = 0x137
WM_CTLCOLORSTATIC = 0x138

OnMessage( WM_CTLCOLOREDIT, "WM_CTLCOLOR" )
OnMessage( WM_CTLCOLORSTATIC, "WM_CTLCOLOR" )

Gui, Add, Edit, w100 hwndHEDIT_1,          ReadWrite
Gui, Add, Edit, w100 hwndHEDIT_2 ReadOnly, ReadOnly
Gui, Show

Gui +LastFound
WinSet, Redraw

Return ;                                        // end of auto-execute section //

WM_CTLCOLOR( wParam, lParam, msg, hwnd  ) 
;hwnd = A handle to destination window.
;wParam = A handle to a display context (DC).
;lParam = A handle to a child window (control).
{
 Static hBrush
 Global BG_COLOR, FG_COLOR

if (lParam = HEDIT_1)
{
   BG_COLOR := 0x000000
   FG_COLOR := 0x00FF00 ; Makes changes to all controls and cannot be modified.
}

if (lParam = HEDIT_2)
{
   BG_COLOR := 0x00FF00
   FG_COLOR := 0x0000FF ; Changes only when focused.
}

IfEqual, hBrush,, SetEnv, hBrush, % DllCall( "CreateSolidBrush", UInt,BG_COLOR )

if (lParam = HEDIT_1){
   DllCall( "SetTextColor", UInt,wParam, UInt,FG_COLOR )
   DllCall( "SetBkColor", UInt,wParam, UInt,BG_COLOR )
   DllCall( "SetBkMode", UInt,wParam, UInt,2 )
   Return hBrush
   }

if (lParam = HEDIT_2){
   DllCall( "SetTextColor", UInt,wParam, UInt,FG_COLOR )
   DllCall( "SetBkColor", UInt,wParam, UInt,BG_COLOR )
   DllCall( "SetBkMode", UInt,wParam, UInt,2 )
   Return hBrush
   }
}
return

GuiClose:
ExitApp


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
==> CtlColors - color your controls by just me
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

rdwray
  • Members
  • 60 posts
  • Last active: Jul 05 2015 11:26 AM
  • Joined: 14 Feb 2012

Looks good, thanks jNizM