A wrapper for AHK's GUI functionality, Experimental!
Requires AHK >= 1.1.20.00 or >= 2.0.a063
A Class that you extend to allow you to turn a Gui or GuiControl into an object (Class).
MyClass := new MyClass()
base.__New(aParams*)
at the start of the __New()
constructor for your class.this.GUI()
, using the same syntax.Gui, Add, Edit, x0 y0 w100, Text
would become this.Gui("Add", "Edit", "x0 y0 w100", "Text")
this.myedit := this.Gui("Add", "Edit", "x0 y0 w100", "Text")
GuiControl
method to manipulate GuiControlsthis.GuiContol("+g", <control>, <method>)
this.GuiControl("+g", this.myedit, this.EditChanged)
myedit.value
. GuiOption
to set gui options, pass objects instead of HWNDs, eg:
this.ChildWindow := new CWindow(this, "-Border")
this.ChildWindow.GuiOption("+Parent", this)
this.ChildWindow := new CWindow(this, "-Border").GuiOption("+Parent", this)
_hwnd
property._parent
property.Because it allows you to write powerful, easy to understand code, like this - 15 commands to set up a Gui with an edit box that saves between runs, plus a couple of gLabels that call class methods, and not a HWND in sight.
; Call base method of class to create window
base.__New()
this.GUI_WIDTH := 200
; Start using GUI commands
this.Gui("Margin",5,5)
; Add some text, dont bother storing result
this.Gui("Add", "Text", "Center xm ym w" this.GUI_WIDTH, "Persistent (Remembered on Reload)")
; Add an Edit box, store a reference on this
this.myedit := this.Gui("Add", "Edit","xm yp+20 w" this.GUI_WIDTH,"ChangeMe")
; Call custom INI routine to tie this Edit box to a settings value.
; This command is likely to be unique to your implementation
; It sets the current value of the control to the value from the settings file, and sets up an event to write settings as they change.
this.myedit.MakePersistent("somename")
; Also set a g-label for this Edit box. Note that this is independent of the Persistence system
this.GuiControl("+g", this.myedit, this.EditChanged)
; Add a Button
this.mybtn := this.Gui("Add","Button","xm yp+30 w" this.GUI_WIDTH,"v Copy v")
; Wire up the button
this.GuiControl("+g", this.mybtn, this.Test) ; pass object to bind g-label to, and method to bind to
; Add an edit box, but don't make it persistent
this.Gui("Add", "Text", "Center xm yp+30 w" this.GUI_WIDTH, "Not Persistent (Lost on Reload)")
this.myoutput := this.Gui("Add","Edit","xm yp+20 w" this.GUI_WIDTH,"")
; Add a child window
; Use GuiOption method to set parent, so we can pass the object instead of the HWND
; Note that we can chain commands.
this.ChildWindow := new CWindow(this, "-Border").GuiOption("+Parent", this)
this.ChildWindow.Gui("Add","Text", "Center x0 y40 w" this.GUI_WIDTH, "CHILD GUI")
this.ChildWindow.Gui("Show", "x2 y150 w" this.GUI_WIDTH " h100")
; Show the main Gui
this.Gui("Show", "h260","Class Test")