Jump to content

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

Colored Controls


  • Please log in to reply
2 replies to this topic
DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
derRaphael posted a way to color controls here. <!-- m -->http://www.autohotke...topic33777.html<!-- m -->

I asked this question in that topic but did not get a reply.

Can anyone assist me on this?


If I have a gui shown and destroyed before the gui I want to change the control colors on then the control colors no longer work.

Change "ShowOpeningScreen" from 1 to 0 to reproduce the issue.

ShowOpeningScreen = 1

If ShowOpeningScreen = 1
 { 
  Gui 2: font, s12
  Gui 2: add, text,,If this screen is shown first the edit control in the next Gui is not colored.
  gui 2: show, autosize, OpeningScreen
  return
 }

2GuiClose:
gui 2: destroy



Gui 1: Add, edit,  w180 h20  vMyEdit  Number,
Control_Colors("MyEdit", "Set", "0xC0C0C0", "0x000000")

Gui 1: +LastFound
GuiID := WinExist()
Control_Colors(GuiID, "RCB", 0, 0)

Gui 1: show, w200 h100, Main Gui
return

GuiClose:
Gui, destroy
ExitApp

Control_Colors(Hwnd, Msg, wParam, lParam = 0)
{
   Critical
    If !(Hwnd+0) {
     GuiControlGet, nHwnd, Hwnd, %Hwnd%
     Hwnd := nhwnd
   }

   Static OldWinProc := ""          ; origin Windowprocedure
   Static NewWinProc := ""          ; new Windowprocedure
   Static SetValue := "Set"         ; take over Values
   Static Register := "RCB"         ; RegisterCallBack
   Static ValueList := ""           ; Values

   ; Aufruf als Fensterprozedur?
   If (A_EventInfo <> NewWinProc) {
      If (Msg = SetValue) {
         If (RegExMatch(ValueList, "m)^" . (Hwnd +0) . "\|")) {
            ValueList := RegExReplace(ValueList
                                     , "m)^" . (Hwnd + 0) . "\|.*$"
                                     , (Hwnd + 0) . "|"
                                     . (wParam + 0) . "|"
                                     . (lParam + 0))
         } Else {
            ValueList .= (Hwnd + 0) . "|"
                      .  (wParam + 0) . "|"
                      .  (lParam + 0) .  "`r`n"
         }
         Return
      }
      If (Msg = Register) {
         If (NewWinProc = "") {
            NewWinProc := RegisterCallback("Control_Colors","",4)
            OldWinProc := DllCall("SetWindowLong"
                                 , UInt, Hwnd
                                 , Int, -4
                                 , Int, NewWinProc
                                 , UInt)
         }
         Return
      }
      Return
   }
   ; 0x0133 : WM_CTLCOLOREDIT
   ; 0x0138 : WM_CTLCOLORSTATIC
   If (Msg = 0x0133 Or Msg = 0x0135 Or Msg = 0x0138) {
      If (RegExMatch(ValueList, "m)^"
                     . (lParam + 0) . "\|(?P<BG>\d+)\|(?P<TX>\d+)$"
                     , C)) {
         DllCall("SetTextColor", UInt, wParam, UInt, CTX)
         DllCall("SetBkColor", UInt, wParam, UInt, CBG)
         Return, DllCall("CreateSolidBrush", UInt, CBG)
      }
   }
   Return DllCall("CallWindowProcA"
                  , UInt, OldWinProc
                  , UInt, Hwnd
                  , UInt, Msg
                  , UInt, wParam
                  , UInt, lParam)
}

I am sure it has something to do with Gui 1: +LastFound, but do not know how to fix it.

Anyone have any ideas in this example how to get the Edit color color to change when the OpeningScreen is shown first?

thanks
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
This is because you need to change default GUI otherwise following won't work:
GuiControlGet, nHwnd, Hwnd, %Hwnd%
;...

Gui 1: Default

Gui 1: Add, edit,  w180 h20  vMyEdit  Number,

Control_Colors("MyEdit", "Set", 0xC0C0C0, 0x000000)

;...


DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

This is because you need to change default GUI otherwise following won't work:

GuiControlGet, nHwnd, Hwnd, %Hwnd%
;...
Gui 1: Default
Gui 1: Add, edit,  w180 h20  vMyEdit  Number,
Control_Colors("MyEdit", "Set", 0xC0C0C0, 0x000000)
;...


That works.

thanks
DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.