-
Notifications
You must be signed in to change notification settings - Fork 33
Using Standard GuiControls in Plugins
UCR allows the Plugin Author to add normal AHK GuiControls (eg EditBoxes, CheckBoxes etc) but have them store their contents between runs. It also provides a handy mechanism for getting notification when the user changes the contents of the GuiControl.
These GuiControls are generally used to allow the end-user to tweak various aspects of the plugin - eg an EditBox might be used to allow the user to type in a number which dictates how quickly a rapid-fire plugin sends output when the input is held.
##Adding a Standard GuiControl
Place a line like the following in your plugin's Init()
method.
this.AddControl(ControlType, ControlName, ChangeValueCallback, Options)
eg this.AddControl("Edit", "MyEdit", this.MyEditChanged.Bind(this), "xm w300")
Parameter | Purpose |
---|---|
ControlType | The type of the GuiControl. This should be one of the AHK Control Names eg Edit or CheckBox
|
ControlName | The name that you wish the control to be known as. |
ChangeValueCallback | A bound function callback that gets executed whenever the GuiControl's contents change. This is basically the same as a "g-label". A value of 0 can be used if you do not wish to be notified on GuiControl change. |
Options | This is the same as the standard AHK option strings used to configure GuiControls and is generally used to configure positioning and size. Do Not pass a hwnd option or any g-labels or v-labels |
##GuiControl callbacks
The ChangeValueCallback parameter allows you to define a function which will be called whenever the GuiControl's content changes.
You must pass a BoundFunc Object.
When triggered, the function will be passed the new value for the GuiControl as the last parameter.
Any parameters that you bind (beyond this) will be passed to the function.
eg if you pass this.MyEditChanged.Bind(this)
, then your function would look like this:
MyEditChanged(value){
value would hold the new value of the GuiControl.
However, if you pass this.MyEditChanged.Bind(this, "MyEdit")
, then your function would look like this:
MyEditChanged(name, value){
name would hold "MyEdit".
value would hold the new value of the GuiControl.
This technique can be used to route the callback for multiple controls to one function - the first parameter tells you which control changed.
##GuiControl Methods
When created, the GuiControl class will be added to the GuiControls
object and be accessible via this.GuiControls.<ControlName>
eg this.GuiControls.MyEdit
###Get()
To get the value of a GuiControl, use the .Get()
method, eg this.GuiControls.MyEdit.Get()
###Set()
To set the value of a GuiControl, use the .Set()
method, eg this.GuiControls.MyEdit.Set("New Value")