Jump to content

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

Control_Colors by derRaphael


  • Please log in to reply
4 replies to this topic
DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Control_Colors by derRaphael found here http://www.autohotke...topic33777.html

 

How can I have 2 Guis with colored controls?

 

Gui 1 has a color editbox, after gui 1 is destroyed I want gui 2 to have a colored editbox.

 

I have tried so many combinations to figure out what is going on, I just can't figure it out.

 

In the example below, the editbox on gui1 has a gray background. When I close Gui 1, gui 1 is destroyed and Gui 2 is created, but the editbox in Gui 2 is not colored.

 

I can get one or the other editbox's colored but not both.

 

Gui 1:default
Gui 1: add, text,cWhite y100 w530 center,Example1
Gui 1: add, edit, x0 y180 w530 h20 vMyControl1 hwndEB1 ReadOnly center, This area should be gray.
Control_Colors("MyControl1", "Set", "0xd8d8d8", "0x000000")
Gui 1: show, y200 w530 h200,Example1
ControlFocus,static1,Example1
Gui 1: color,000000

WinGet,Example1ID,ID,Example1
Control_Colors(Example1ID, "RCB", 0, 0)
return

GuiClose:
Gui 1: destroy

Gui 2:default
Gui 2: add, text,cWhite y100 w530 center,Example2
Gui 2: add, edit, x0 y180 w530 h20 vMyControl2 hwndEB2 ReadOnly center, This area should be gray.
Control_Colors(MyControl2, "Set", "0xd8d8d8", "0x000000")
Gui 2: show, y500 w530 h200,Example2
ControlFocus,static1,Example2
Gui 2: color, 000000

WinGet,Example2ID,ID,Example2
Control_Colors(Example2ID, "RCB", 0, 0)
return

2GuiClose:
exitapp
return

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)
}
return
   

 

On the first Gui the following code from the function retrieves the control hwnd properly, but after destroying gui 1 and creating gui 2, the GuiControlGet in the function is retrieving a blank hwnd . I checked and the script is passing the correct window ID to the function each time it is called.

    If !(Hwnd+0) {
     GuiControlGet, nHwnd, Hwnd, %Hwnd%
     Hwnd := nhwnd

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

just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

You might pass the Edit's HWND (EB2) to resolve the first problem. But there is another glitch:

 

      If (Msg = Register) {
         If (NewWinProc = "") {
            NewWinProc := RegisterCallback("Control_Colors","",4)
            OldWinProc := DllCall("SetWindowLong"
                                 , UInt, Hwnd
                                 , Int, -4
                                 , Int, NewWinProc
                                 , UInt)
         }
         Return

 

will allow to register the callback only once: If (NewWinProc = "")

 

Edit: Something I've overlooked:

Control_Colors(MyControl2, "Set", "0xd8d8d8", "0x000000")

You have to pass the variable's name as a string: "MyControl2".


Prefer ahkscript.org for the time being.


just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
You're using a very "ancient" version of Control_Colors(), subclassing the whole GUI which isn't needed. You might try this shortened version using OnMessage()  instead:
 
#NoEnv
SetBatchLines, -1
WM_CTLCOLOREDIT    := 0x0133
WM_CTLCOLORLISTBOX := 0x0134
WM_CTLCOLORSTATIC  := 0x0138

OnMessage(WM_CTLCOLOREDIT, "Control_Colors")
OnMessage(WM_CTLCOLORSTATIC, "Control_Colors")

Gui 1: Default
Gui 1: Color, 000000
Gui 1: Add, Text,cWhite y100 w530 Center, Example1
Gui 1: Add, Edit, x0 y180 w530 h20 vMyControl1 hwndEB1 ReadOnly Center, This area should be gray.
Control_Colors("MyControl1", "Set", "0xd8d8d8", "0x000000")
Gui 1: Show, y200 w530 h200, Example1
ControlFocus, Static1, Example1
Gui, +LastFound
Return

GuiClose:
Gui 1: Destroy

Gui 2: Default
Gui 2: Color, 000000
Gui 2: Add, Text,cWhite y100 w530 Center, Example2
Gui 2: Add, Edit, x0 y180 w530 h20 vMyControl2 hwndEB2 ReadOnly Center, This area should be gray.
Control_Colors("MyControl2", "Set", "0xd8d8d8", "0x000000")
Gui 2: Show, y500 w530 h200, Example2
ControlFocus, Static1, Example2
Return

2GuiClose:
ExitApp

Control_Colors(wParam, lParam, Msg, Hwnd) {
   Static Controls := {}
   If (lParam = "Set") {
      If !(CtlHwnd := wParam + 0)
         GuiControlGet, CtlHwnd, Hwnd, %wParam%
      If !(CtlHwnd + 0)
         Return False
      Controls[CtlHwnd, "CBG"] := Msg + 0
      Controls[CtlHwnd, "CTX"] := Hwnd + 0
      Return True
   }
   ; Critical
   If (Msg = 0x0133 Or Msg = 0x0134 Or Msg = 0x0138) {
      If Controls.HasKey(lParam) {
         If (Controls[lParam].CTX >= 0)
            DllCall("Gdi32.dll\SetTextColor", "Ptr", wParam, "UInt", Controls[lParam].CTX)
         DllCall("Gdi32.dll\SetBkColor", "Ptr", wParam, "UInt", Controls[lParam].CBG)
         Return DllCall("Gdi32.dll\CreateSolidBrush", "UInt", Controls[lParam].CBG)
      }
   }
}

Prefer ahkscript.org for the time being.


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

Thanks for the reply.

 

Your updated code works.

 

Even with MyControl2 as "MyControl2" it still would not work. I had tried so many combinations that I forgot to put the quotes back on.

 

TedStriker posted a link on derRaphaels control_colors thread to an updated version on the german website but the link is dead.

 

Can you post your version on derRaphaels control_colors thread? It sure would help others.

 

derRaphaels control_colors thread http://www.autohotke...bitmaps-needed/


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

jleslie48
  • Members
  • 145 posts
  • Last active: Sep 28 2017 07:13 PM
  • Joined: 29 Jun 2010

ok, here's the next thought:   how do I make the background color transparent?   the control_colors lets me change colors of a gui, add, edit, readonly box, but my  edit box is on top of an image and I want the image to show through the edit box.