GuiControl_Ex - Extending GuiControls - 2023/04/03 - v2.0.2

Post your working scripts, libraries and tools.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by AHK_user » 26 Oct 2021, 15:30

Oh, I just realised that we can also add some darkmode methods :D .
Setting the title in dark mode. [Gui.SetDarkTitle()]
Setting the Menu in dark mode [Gui.SetDarkMenu()] (this actually sets all the menus of the script in darkmode, I do not know if it is acceptable)
Setting Edit, Buttons and listbox controls in dark mode (only changes the scrollbar, but the effect is nice) [Gui.Control.SetDarkMode()]

:think: In the current script, I added a SetDarkMode() method to all the controls. But as it only effects Button, Edit and Listbox (or was is listview?) maybe it is better to add the method only to these controlls, so that an error will display if the method is set to a control that has no change from it.

:think: we could also add a general gui.SetDarkMode() that loops over all the controlls and sets them all to darkmode. (By my experience, this only affects button, listbox end edit with a scrollbar.) This would only affect the already existing controls.

Code: Select all

; Thanks to jNizM for the interesting DllCalls
; https://www.autohotkey.com/boards/viewtopic.php?t=70852
class Edit_ext {
    Static __New() {
        Gui.Edit.Prototype.SetCue:= ObjBindMethod(this, "SetCue")
    }

    Static SetCue(_obj, string, option := true) {
        ; Links ....................:  https://docs.microsoft.com/en-us/windows/win32/controls/em-setcuebanner
        ; Description ..............:  Sets the textual cue, or tip, that is displayed by the edit control to prompt the user for information.
        ; Option ...................:  True  -> if the cue banner should show even when the edit control has focus
        ;                              False -> if the cue banner disappears when the user clicks in the control
        static ECM_FIRST := 0x1500
        static EM_SETCUEBANNER := ECM_FIRST + 1
        if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", EM_SETCUEBANNER, "int", option, "str", string, "int"))
            return true
        return false
    }

}

class ComboBox_ext {
    Static __New() {
        Gui.ComboBox.Prototype.SetCue := ObjBindMethod(this, "SetCue")
    }

    Static SetCue(_obj, string, option := true) {
        ; Links ....................:  https://docs.microsoft.com/en-us/windows/win32/controls/cb-setcuebanner
        ; Description ..............:  Sets the cue banner text that is displayed for the edit control of a combo box.
        static CBM_FIRST := 0x1700
        static CB_SETCUEBANNER := CBM_FIRST + 3
        if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", CB_SETCUEBANNER, "int", option, "str", string, "int"))
            return true
        return false
    }
}

class Control_ext {
    Static __New() {
        Gui.Control.Prototype.SetDarkMode := ObjBindMethod(this, "SetDarkMode")
    }

    Static SetDarkMode(_obj) {
        ; This has the following effect:
        ; Button => dark button
        ; Edit => if row>1 dark scrollbar
        ; Listbox => dark scrollbar
        if (DllCall("uxtheme\SetWindowTheme", "ptr", _obj.hwnd, "str", "DarkMode_Explorer", "ptr", 0))
            return true
        return false
    }
}

class Gui_ext {
    Static __New() {
        Gui.Prototype.SetDarkTitle := ObjBindMethod(this, "SetDarkTitle")
        Gui.Prototype.SetDarkMenu := ObjBindMethod(this, "SetDarkMenu")
    }

    Static SetDarkTitle(_obj) {
        if VerCompare(A_OSVersion, "10.0.17763") >= 0 {
            attr := 19
            if VerCompare(A_OSVersion, "10.0.18985") >= 0 {
                attr := 20
            }
            if (DllCall("dwmapi\DwmSetWindowAttribute", "ptr", _obj.hwnd, "int", attr, "int*", true, "int", 4))
               return true 
        }
        return false
    }
    
    Static SetDarkMenu(_obj) {
        uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
        SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
        FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
        DllCall(SetPreferredAppMode, "int", 1)	; Dark
        if DllCall(FlushMenuThemes)
            return true
        return false
    }
}

MyGui := Gui()

Edt01 := MyGui.AddEdit("w300 r3")
Edt01.SetCue("Edit Control Cue Text")
Edt01.SetDarkMode()
Edt02 := MyGui.AddComboBox("w300", ["test 1", "test 2"])
Edt02.SetCue("Enter text here") 
Bttn01 := MyGui.AddButton(,"OK")
Bttn01.SetDarkMode()
MyGui.SetDarkTitle()
MyGui.SetDarkMenu()
MyGui.Show()
Attachments
2021-10-26 22_27_02-Window.png
2021-10-26 22_27_02-Window.png (17.56 KiB) Viewed 5169 times
Last edited by AHK_user on 27 Oct 2021, 05:28, edited 5 times in total.

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by AHK_user » 26 Oct 2021, 16:00

OK, the last post for today.

Gui.EnableToolTip(DelayMs := 500) :dance: ?

=> This displays tooltips for every control that has the property tooltip.
Current flaws:
- When moving the mouse fast outside the gui, it sometimes stays visible.
- Maybe creating custom tooltip to be able to change the colors?
- I did not manage to include WM_MOUSEMOVE_Tooltip inside the Gui_ext, does somebody knows how to do this?

Another idea/variant could be Gui.EnableStatusbar(Section) that does something similar but then with controls with the control.Statusbar property.

Code: Select all

; Thanks to jNizM for the interesting DllCalls
; https://www.autohotkey.com/boards/viewtopic.php?t=70852
class Edit_ext {
    Static __New() {
        Gui.Edit.Prototype.SetCue:= ObjBindMethod(this, "SetCue")
    }

    Static SetCue(_obj, string, option := true) {
        ; Links ....................:  https://docs.microsoft.com/en-us/windows/win32/controls/em-setcuebanner
        ; Description ..............:  Sets the textual cue, or tip, that is displayed by the edit control to prompt the user for information.
        ; Option ...................:  True  -> if the cue banner should show even when the edit control has focus
        ;                              False -> if the cue banner disappears when the user clicks in the control
        static ECM_FIRST := 0x1500
        static EM_SETCUEBANNER := ECM_FIRST + 1
        if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", EM_SETCUEBANNER, "int", option, "str", string, "int"))
            return true
        return false
    }
}

class ComboBox_ext {
    Static __New() {
        Gui.ComboBox.Prototype.SetCue := ObjBindMethod(this, "SetCue")
    }

    Static SetCue(_obj, string, option := true) {
        ; Links ....................:  https://docs.microsoft.com/en-us/windows/win32/controls/cb-setcuebanner
        ; Description ..............:  Sets the cue banner text that is displayed for the edit control of a combo box.
        static CBM_FIRST := 0x1700
        static CB_SETCUEBANNER := CBM_FIRST + 3
        if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", CB_SETCUEBANNER, "int", option, "str", string, "int"))
            return true
        return false
    }
}

class Control_ext {
    Static __New() {
        Gui.Control.Prototype.SetDarkMode := ObjBindMethod(this, "SetDarkMode")
    }

    Static SetDarkMode(_obj) {
        ; This has the following effect:
        ; Button => dark button
        ; Edit => if row>1 dark scrollbar
        ; Listbox => dark scrollbar
        if (DllCall("uxtheme\SetWindowTheme", "ptr", _obj.hwnd, "str", "DarkMode_Explorer", "ptr", 0))
            return true
        return false
    }
}

class Gui_ext {
    Static __New() {
        Gui.Prototype.SetDarkTitle := ObjBindMethod(this, "SetDarkTitle")
        Gui.Prototype.SetDarkMenu := ObjBindMethod(this, "SetDarkMenu")
        Gui.Prototype.EnableToolTip := ObjBindMethod(this, "EnableToolTip")
    }
    
    Static EnableToolTip(_obj,DelayMs :=500) {
        OnMessage(0x200, WM_MOUSEMOVE_Tooltip.Bind(DelayMs))
    }

    Static SetDarkTitle(_obj) {
        if VerCompare(A_OSVersion, "10.0.17763") >= 0 {
            attr := 19
            if VerCompare(A_OSVersion, "10.0.18985") >= 0 {
                attr := 20
            }
            if (DllCall("dwmapi\DwmSetWindowAttribute", "ptr", _obj.hwnd, "int", attr, "int*", true, "int", 4))
               return true 
        }
        return false
    }

    Static SetDarkMenu(_obj) {
        uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
        SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
        FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
        DllCall(SetPreferredAppMode, "int", 1)	; Dark
        if DllCall(FlushMenuThemes)
            return true
        return false
    }
}


MyGui := Gui()

Edt01 := MyGui.AddEdit("w300 r3")
Edt01.SetCue("Edit Control Cue Text")
Edt01.SetDarkMode()
Edt01.Tooltip := "Cool ToolTip"
Edt02 := MyGui.AddComboBox("w300", ["test 1", "test 2"])
Edt02.SetCue("Enter text here") 
Bttn01 := MyGui.AddButton(,"OK")
Bttn01.Tooltip := "What a nice button!"
Bttn01.SetDarkMode()
MyGui.SetDarkTitle()
MyGui.SetDarkMenu()
MyGui.EnableToolTip(10)
MyGui.Show()


return

   WM_MOUSEMOVE_Tooltip(DelayMs, wParam, lParam, Msg, Hwnd) {
       static PrevHwnd := 0
       static HoverControl := 0

       ; Setting the tooltips for controls with a property tooltip
       if (Hwnd != PrevHwnd) {
           Text := "", ToolTip()	; Turn off any previous tooltip.
           currControl := GuiCtrlFromHwnd(Hwnd)
           if CurrControl {
               if !CurrControl.HasProp("ToolTip")
                   return	; No tooltip for this control.
               CheckHoverControl := () => hwnd != prevHwnd ? (SetTimer(DisplayToolTip, 0), SetTimer(CheckHoverControl, 0)) : ""
               DisplayToolTip := () => (ToolTip(CurrControl.ToolTip), SetTimer(CheckHoverControl, 0))
               SetTimer(CheckHoverControl, 50)	; Checks if hovered control is still the same
               SetTimer(DisplayToolTip, -DelayMs)
           }
           PrevHwnd := Hwnd
       }
       return
   }
Last edited by AHK_user on 27 Oct 2021, 02:42, edited 1 time in total.

User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by hoppfrosch » 27 Oct 2021, 01:57

@AHK_user : Your code above has still a bug:

Code: Select all

; ERROR: Edt01.NewMethod("Edit Control Cue Text")
; CORRECT:
Edt01.SetCue("Edit Control Cue Text")

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by jNizM » 27 Oct 2021, 02:35

You can also use the buildin sendmessage function
See viewtopic.php?f=92&t=93379 (in Tips and Tricks for v2)

But since SetCue it is in wishlist I hope it will be buildin soon too
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by AHK_user » 27 Oct 2021, 05:24

hoppfrosch wrote:
27 Oct 2021, 01:57
@AHK_user : Your code above has still a bug:

Code: Select all

; ERROR: Edt01.NewMethod("Edit Control Cue Text")
; CORRECT:
Edt01.SetCue("Edit Control Cue Text")
Thanks, I fixed it in the post.

iPhilip
Posts: 809
Joined: 02 Oct 2013, 12:21

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by iPhilip » 16 Nov 2021, 17:55

AHK_user wrote:
26 Oct 2021, 12:22
One question, does somebody knows hot to change this so it is set by the property "CueText" and not by a method?
Like:
Edt01.CueText:= "Edit Control Cue Text"

This way you can only add one parameter, but It would be cool to know If this is possible.
See the two classes and the example below:

Code: Select all

class Edit_Ext
{
   static __New() {
      Gui.Edit.Prototype.DefineProp("CueText", {Get:this.Prototype.CueText, Set:this.Prototype.CueText})
   }
   
   CueText(Params*) {
      static EM_SETCUEBANNER := 0x1501
      if !Params.Length {
         try
            return this._CueText
         catch
            throw PropertyError("Undefined Gui Edit property.", -1, "CueText")
      } else if SendMessage(EM_SETCUEBANNER, Params.Length = 2 ? Params[2] : 0, StrPtr(Params[1]), , this.hwnd)
         return this._CueText := Params[1]
      else
         throw OSError("EM_SETCUEBANNER message failed.", -1)
   }
}

class ComboBox_Ext
{
   static __New() {
      Gui.ComboBox.Prototype.DefineProp("CueText", {Get:this.Prototype.CueText, Set:this.Prototype.CueText})
   }
   
   CueText(Params*) {
      static CB_SETCUEBANNER := 0x1703
      if !Params.Length {
         try
            return this._CueText
         catch
            throw PropertyError("Undefined Gui ComboBox property.", -1, "CueText")
      } else if SendMessage(CB_SETCUEBANNER, 0, StrPtr(Params[1]), , this.hwnd)
         return this._CueText := Params[1]
      else
         throw OSError("CB_SETCUEBANNER message failed.", -1)
   }
}

MyGui := Gui()
EditCtrl := MyGui.Add("Edit", "w200")
ComboBoxCtrl := MyGui.Add("ComboBox", "w200", ["Red","Green","Blue","Black","White"])
; EditCtrl.CueText[true] := "Edit Control Cue Text..."
EditCtrl.CueText := "Edit Control Cue Text..."
ComboBoxCtrl.CueText := "ComboBox Control Cue Text..."
MyGui.OnEvent("Close",  (*) => ExitApp())
MyGui.OnEvent("Escape", (*) => ExitApp())
MyGui.Show()
By the way, unlike the EM_SETCUEBANNER message, the CB_SETCUEBANNER message requires that wParam be zero.

I hope this helps.

- iPhilip

EDIT: Expanded error handling.
Last edited by iPhilip on 17 Nov 2021, 11:09, edited 2 times in total.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2021/06/21 - beta.1

Post by AHK_user » 17 Nov 2021, 06:25

iPhilip wrote:
16 Nov 2021, 17:55
AHK_user wrote:
26 Oct 2021, 12:22
One question, does somebody knows hot to change this so it is set by the property "CueText" and not by a method?
Like:
Edt01.CueText:= "Edit Control Cue Text"

This way you can only add one parameter, but It would be cool to know If this is possible.
See the two classes and the example below:

Code: Select all

class Edit_Ext
{
   static __New() {
      Gui.Edit.Prototype.DefineProp("CueText", {Get:this.Prototype.CueText, Set:this.Prototype.CueText})
   }
   
   CueText(Params*) {
      static EM_SETCUEBANNER := 0x1501
      try if !Params.Length
         return this._CueText
      else if SendMessage(EM_SETCUEBANNER, Params.Length = 2 ? Params[2] : 0, StrPtr(Params[1]), , this.hwnd)
         return this._CueText := Params[1]
      throw PropertyError("Undefined property.", -1, "CueText")
   }
}

class ComboBox_Ext
{
   static __New() {
      Gui.ComboBox.Prototype.DefineProp("CueText", {Get:this.Prototype.CueText, Set:this.Prototype.CueText})
   }
   
   CueText(Params*) {
      static CB_SETCUEBANNER := 0x1703
      try if !Params.Length
         return this._CueText
      else if SendMessage(CB_SETCUEBANNER, 0, StrPtr(Params[1]), , this.hwnd)
         return this._CueText := Params[1]
      throw PropertyError("Undefined property.", -1, "CueText")
   }
}

MyGui := Gui()
EditCtrl := MyGui.Add("Edit", "w200")
ComboBoxCtrl := MyGui.Add("ComboBox", "w200", ["Red","Green","Blue","Black","White"])
; EditCtrl.CueText[true] := "Edit Control Cue Text..."
EditCtrl.CueText := "Edit Control Cue Text..."
ComboBoxCtrl.CueText := "ComboBox Control Cue Text..."
MyGui.OnEvent("Close",  (*) => ExitApp())
MyGui.OnEvent("Escape", (*) => ExitApp())
MyGui.Show()
By the way, unlike the EM_SETCUEBANNER message, the CB_SETCUEBANNER message requires that wParam be zero.

I hope this helps.

- iPhilip
Thanks @iPhilip, I tested it and it works perfectly.
Very cool what you can do with v2 :D

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 01 Jan 2022, 08:57

Update 2022/01/01
  • separated ListBox and ComboBox classes
  • .AddPicButton() method now accepts text as 4th parameter
  • text + icon works for PicButton and SplitButton (but not for ToggleButton) - thanks to @just me for this one
  • added .CueText property for Edit and ComboBox control (thanks to @AHK_user and @iPhilip)
  • added .SetCueText() for Edit control. This allows to set the option for making the cue persist on control focus.
  • updated README
Last edited by TheArkive on 01 Jan 2022, 10:06, edited 2 times in total.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 01 Jan 2022, 09:04

Forgot to implement the cue as a property for easy set/get... doing that now.

Repo/credits/OP updated for .CueText property.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 02 Jan 2022, 02:28

@iPhilip

Did your version happen to somehow take 2 params when setting EditCtrl.CueText? It looks like it only takes 1 param.

Just curious what I might be missing, if anything...

iPhilip
Posts: 809
Joined: 02 Oct 2013, 12:21

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by iPhilip » 02 Jan 2022, 04:37

TheArkive wrote:
02 Jan 2022, 02:28
@iPhilip

Did your version happen to somehow take 2 params when setting EditCtrl.CueText? It looks like it only takes 1 param.

Just curious what I might be missing, if anything...
@TheArkive, There is a difference between the EM_SETCUEBANNER and the CB_SETCUEBANNER messages. I tried to bring attention to that in my note below the code:
iPhilip wrote:
16 Nov 2021, 17:55
By the way, unlike the EM_SETCUEBANNER message, the CB_SETCUEBANNER message requires that wParam be zero.
In fact, when setting EditCtrl.CueText there are two parameters: the cue banner text (Params[1]) and the optional boolean parameter (Params[2]) that determines if the cue banner should show even when the edit control has focus. On the other hand, when setting ComboBoxCtrl.CueText there is only one parameter: the cue banner text (Params[1]). The wParam parameter must be 0 (reference).

Note that @AHK_user in his post mistakenly allows wParam in the ComboBox to be non-zero.

I hope this helps. Let me know if you have any additional questions.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 02 Jan 2022, 04:44

@iPhilip

Right, that all makes sense (difference between Combo and Edit and wParam as "required zero" and "1 or zero" respectively).

I think this is more of an AHK v2 question, not so much a controls question.

I don't see a use case where your code would be able to pass a value to the wParam in the case of the Edit control. Even though you define the .CueText() method, it appears to be overwritten by the DefineProp line, thus changing the method into a property.

I know a Property[can, accept, params] ... but i don't see that usage either. How does one pass a 0 or 1 to wParam for the Edit control in your example and/or the CueText to the .CueText property?

iPhilip
Posts: 809
Joined: 02 Oct 2013, 12:21

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by iPhilip » 02 Jan 2022, 13:52

@TheArkive
TheArkive wrote:
02 Jan 2022, 04:44
I don't see a use case where your code would be able to pass a value to the wParam in the case of the Edit control.
Perhaps, this slight modification to the Edit_Ext class will help you see that it's actually being done. Try running it.

Code: Select all

class Edit_Ext
{
   static __New() {
      Gui.Edit.Prototype.DefineProp("CueText", {Get:this.Prototype.CueText, Set:this.Prototype.CueText})
   }
   
   CueText(Params*) {
      static EM_SETCUEBANNER := 0x1501
      if !Params.Length {
         try
            return this._CueText
         catch
            throw PropertyError("Undefined Gui Edit property.", -1, "CueText")
      } else if SendMessage(EM_SETCUEBANNER, Params.Length = 2 ? Params[2] : 0, StrPtr(Params[1]), , this.hwnd) {
         MsgBox "Cue banner text: " Params[1] (Params.Length = 2 ? "`nwParam = " Params[2] : "")
         return this._CueText := Params[1]
      }
      else
         throw OSError("EM_SETCUEBANNER message failed.", -1)
   }
}
MyGui := Gui()
EditCtrl := MyGui.Add("Edit", "w200")
EditCtrl.CueText[true] := "Edit Control Cue Text..."
MsgBox EditCtrl.CueText "`n" EditCtrl._CueText
MyGui.OnEvent("Close",  (*) => ExitApp())
MyGui.OnEvent("Escape", (*) => ExitApp())
MyGui.Show()
TheArkive wrote:
02 Jan 2022, 04:44
Even though you define the .CueText() method, it appears to be overwritten by the DefineProp line, thus changing the method into a property.
The class defines the CueText() method. It also defines two properties of the Edit control: the CueText and the _CueText property. (The _CueText property is used to remember the string). The properties belong to a different object than the method.
For reference, AHK v2 (but not AHK v1) allows class methods and properties to have the same name as demonstrated in the following:

Code: Select all

class foo
{
   __New() {
      this._bar := 3
   }
   
   bar() {
      MsgBox "You called method " A_ThisFunc
   }
   
   bar => "You called the property getter " A_ThisFunc "`nThe value of the property is " this._bar
}
o := foo()
o.bar()
MsgBox o.bar
MsgBox o._bar
TheArkive wrote:
02 Jan 2022, 04:44
I know a Property[can, accept, params] ... but i don't see that usage either.
That syntax would set a property of the class itself. In this case, I am setting a property of the Edit control object using the CueText() method of the class.

I hope the above is helpful.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 02 Jan 2022, 16:40

@iPhilip

Now I get it, thanks :)

I had not realized that properties and methods could have the same name.

I also didn't think to check the order of parameters within the .CueText() method when doing class.prop[param] := value.

Thanks

iPhilip
Posts: 809
Joined: 02 Oct 2013, 12:21

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by iPhilip » 02 Jan 2022, 19:13

You are welcome. :)
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/01 - beta.3

Post by TheArkive » 08 Jan 2022, 15:10

Update 2022/01/08
  • added props/methods to Edit: SelText, SelStart, SelEnd, SetSel(), SetCueText()
  • added props/methods to Combo: SelText, SelStart, SelEnd, SetSel() check_match()
  • added prop to Combo: AutoComplete (true/false)
  • added an extension for Gui to facilitate AutoComplete for combo, and other fututre expansions
  • fixed credits & comments (if I miss one please let me know)
  • renamed a few internal properties/methods for these changes
  • updated README

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/09 - beta.3

Post by TheArkive » 09 Jan 2022, 15:14

Update 2022/01/09
  • changed behavior of Combo and Edit .SetSel(), see docs
  • updated README, added detail for Combo and Edit .CueText
  • updated README.html

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2022/01/09 - beta.3

Post by AHK_user » 24 Apr 2022, 12:34

@TheArkive What is your opinion to add the Toolbar to this library?

You have created Iron_Toolbar that seems to have a lot of options, we could use that.
https://github.com/TheArkive/IronToolbar_AHK

I would however try to keep a similar syntax as in the standard Gui methods, so some methods should change.
ToolbarObject := GuiObj.AddToolbar(Options := "Flat List ToolTips",arrayButtons, ImageList)
ToolbarObject.OnEvent("Click", CallBack)

The options can be used to set the general options and change the default options.
arrayButtons would have 2 possibilities:
Possibility 1:
An array of strings: The strings would be used as the label texts (Short method)
example: ["button 1","button 2"]
The used Icons would be simply the same index of the imagelist, empty strings are separators and are not counted.
Possibility 2:
An array of objects: The object would have the following properties (longer method with more possibilities)
- text : Text of label
- icon : number of Icon in iconlist (if not present, just use the same index as the Imagelist, skip separators)
- option : individual options of the buttons (if not present, use the same options as toolbar options)

Just for information, I have created parallel a conversion of another similar simpler toolbar script that is shorter, maybe interesting to compare and merge some methods.
viewtopic.php?f=82&t=103004

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: GuiControl_Ex - Extending GuiControls - 2022/01/09 - beta.3

Post by TheArkive » 25 Apr 2022, 13:53

@AHK_user

I don't know about "adding" a toolbar to this, since a toolbar is far more complex. But I do agree that I can modify my toolbar lib to be more standard. I can modify the Gui.Add() method to handle a "toolbar" type so that Gui.AddToolbar() and Gui.Add("Toolbar",...) work as expected.

EDIT: I'm a doof, I see what you mean about changing the obj to an array. It's basically the same as I have it now, but not using an object. I could do that i suppose.

I will definitely check our your final toolbar script more carefully. I like how short it looks :) I don't deny it, I probably went a bit too far in trying to "make a toolbar easy". I actually have changed many things about my coding style since I made IronToolbar. It may be due for a rewrite, and then maybe I can finally simplify a few more things, and fix a few things I had to work around.

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: GuiControl_Ex - Extending GuiControls - 2022/01/09 - beta.3

Post by AHK_user » 25 Apr 2022, 15:55

@TheArkive
Your code seems amazing, I just converted mine to V2, and cleaned it up during the process. (And got a lot of learningfull help.)
I even do not have tested the options, there was no documentation in the original script :lol: :lol: :lol:

:think: :think: :think:

Another idea is to see the toolbar more similar to the menubar syntax, define the buttons seperately and connect the toolbar to the gui

Something like:

Code: Select all

MyToolbar := Toolbar(generaloptions)
oToolbarButton1 := MyToolbar.Add(options, "buttontext 1", callback1, IconNumber, PartNumber)
oToolbarButton2 := MyToolbar.Add(options, "buttontext 2", callback2, IconNumber, PartNumber)
MyGui.ToolBar := MyToolbar 

callback1(GuiObject,ToolbarObject){
	MsgBox(ToolbarObject.text)
}

callback2(GuiObject,ToolbarObject){
}
This seems logical ahk syntax and gives flexibility for later expansion, setting,... :D

Post Reply

Return to “Scripts and Functions (v2)”