Documentation¶
GuiBase¶
The GuiBase
class is the main class that represents a GUI.
It can either be instantiated directly, or you can extend upon it for more complicated GUIs. See the examples.
-
GuiBase.
__Version
¶ Contains the installed version of the library.
-
class
GuiBase
¶ Represents a GUI object.
-
Title
¶ Get or set the window title.
-
hwnd
¶ Contains the window handle.
-
ahk_id
¶ Shorthand for
"ahk_id" . hwnd
-
Visible
¶ Bool indicating whether the window is visible or hidden.
-
BackgroundColor
¶ Get or set the background color.
-
ControlColor
¶ Get or set the control (foreground) color.
-
Controls
¶ An array of all control instances the GUI instance has created.
-
Position
¶ Instance of
GuiBase.WindowPosition
representing the position and size of the GUI window.
-
__New
(Title := "AutoHotkey Window", Options := "")¶ Creates a new instance of the class.
Note
You shouldn’t call this meta-function directly, but use the
new
keyword. See the AutoHotkey documentation on constructing and deconstructing objects.Parameters: - Title – Title of the window.
- Options – Options string.
Returns: A
GuiBase
instance.
-
Show
(Options := "")¶ Shows the GUI window.
Parameters: Options – Options string.
-
Hide
(Options := "")¶ Hides the GUI window.
Parameters: Options – Options string.
-
Destroy
(Options := "")¶ Destroys the GUI, and frees all
GuiBase.ControlType
instances related to it. It’s a good idea to clear all references you have kept yourself so the GuiBase instance can be freed properly.
-
Options
(Options)¶ Change the options of the GUI.
Parameters: Options – Options string.
-
SetDefault
()¶ Sets this GUI as the default GUI.
-
SetDefaultListView
(ListView)¶ Sets the default ListView control.
Parameters: ListView – GuiBase.ListViewControl
instance.
-
Control
(Command := "", Control := "", ControlParams := "")¶ Calls GuiControl.
Parameters: - Command – The GuiControl command to perform.
- Control – The control instance to apply the command on.
- ControlParams – The parameters for the command.
-
GetControl
(hwnd)¶ Gets a control instance.
Parameters: hwnd – hwnd of the control. Returns: A control instance, if found.
-
Margins
(x := "", y := "")¶ Sets the control spacing margins for newly created controls.
Parameters: - x – Horizontal spacing.
- y – Vertical spacing.
-
Font
(Options := "", Font := "")¶ Changes the font for newly created controls.
Parameters: - Options – Options string.
- Font – Font name.
-
Focus
()¶ Focuses the GUI window.
-
Enable
()¶ Enables the GUI window if previously disabled.
-
Disable
()¶ Disables the GUI window if previously enabled.
-
SetIcon
(Icon)¶ Changes the GUI window icon.
Parameters: Icon – Path to an icon file.
-
AddText
(Options := "", Text := "")¶ Adds a text control.
Parameters: - Options – Options string.
- Text – Text contents of the control.
Returns: GuiBase.TextControl
instance.
-
AddButton
(Options := "", Text := "")¶ Adds a text control.
Parameters: - Options – Options string.
- Text – Text contents of the control.
Returns: GuiBase.ButtonControl
instance.
-
AddEdit
(Options := "", Text := "")¶ Adds an edit control.
Parameters: - Options – Options string.
- Text – Text contents of the control.
Returns: GuiBase.EditControl
instance.
-
AddListView
(Options := "", Headers := "")¶ Adds a ListView control.
Parameters: - Options – Options string.
- Headers – Either an array of header names, or a string of header names separated by
|
(pipe).
Returns: GuiBase.ListViewControl
instance.
-
AddStatusBar
(Options := "", Text := "")¶ Adds a statusbar.
Parameters: - Options – Options string.
- Text – Text contents of the control.
Returns: GuiBase.StatusBarControl
instance.
-
Base types¶
ControlType¶
-
class
GuiBase.
ControlType
¶ Represents a GUI control object.
-
Gui
¶ Reference to the GUI instance that created this instance.
-
hwnd
¶ Handle of the control.
-
Position
¶ GuiBase.ControlPosition
instance.
-
__New
(Gui, Options := "", Text := "")¶ Creates a new control instance.
Note
Don’t construct control instances directly, use the methods in
GuiBase
.Parameters: - Gui – The GUI instance that created this control.
- Options – Options string.
- Text – Inital text contents of the control, if applicable.
Returns: An indirect reference to the control instance.
-
Options
(Options)¶ Change the options/settings of the control.
Parameters: Options – Options string.
-
Control
(Command := "", Options := "")¶ Calls the GuiControl command.
Parameters: - Command – The action to do. See documentation link above.
- Options – Param3 in the documentation link above.
-
OnEvent
(Func := "")¶ Makes the control call
Func
when an event happens.Parameters: Func – Function reference or boundfunc to call when events happen. :return: The control instance.
-
ContentControlType¶
-
class
GuiBase.
ContentControlType
¶ This class extends
GuiBase.ControlType
Represents a control with a singular content field, such as
GuiBase.TextControl
,GuiBase.ButtonControl
andGuiBase.EditControl
-
Text
¶ Get or set the contents of the control.
-
GetText
()¶ Returns: The text contents of the control.
-
SetText
(Text)¶ Parameters: Text – New contents of the control.
-
Control types¶
TextControl¶
-
class
GuiBase.
TextControl
¶ This class extends
GuiBase.ContentControlType
-
Type
¶ The type of control, contains
"Text"
-
ButtonControl¶
-
class
GuiBase.
ButtonControl
¶ This class extends
GuiBase.ContentControlType
-
Type
¶ The type of control, contains
"Button"
-
EditControl¶
-
class
GuiBase.
EditControl
¶ This class extends
GuiBase.ContentControlType
-
Type
¶ The type of control, contains
"Edit"
-
ListViewControl¶
-
class
GuiBase.
ListViewControl
¶ This class extends
GuiBase.ControlType
-
Type
¶ The type of control, contains
"ListView"
-
RowCount
¶ Contains the amount of rows.
-
ColumnCount
¶ Contains the amount of columns.
-
SelectedCount
¶ Contains the amount of selected rows.
-
ImageList
¶ Contains an
GuiBase.ImageList
instance if one is assigned to the listview viaSetImageList
.
-
Add
(Options := "", Fields*)¶ Adds a row to the listview.
Parameters: - Options – Options string.
- Fields* – Variadic parameter array of field contents.
-
Insert
(Row, Options := "", Fields*)¶ Identical to
Add()
but with an additional parameterRow
Parameters: Row – Which row to insert the new row at.
-
Delete
(Row := "")¶ Deletes one or all rows.
Parameters: Row – If blank all rows are deleted, otherwise the row number specified. Returns: Selected row count of the listview.
-
GetSelected
()¶ Gets all the rows that are selected.
Returns: An array of all the row numbers that are selected.
-
GetChecked
()¶ Gets all the rows that are checked.
Returns: An array of all the row numbers that are checked.
-
SetImageList
(ImageList)¶ Set an imagelist for the listview.
Parameters: ImageList – An GuiBase.ImageList
instance.
-
GetNextSelected
(Start := 0)¶ Gets the next selected row after
Start
.Returns: Row number of the next selected row.
-
GetNextChecked
(Start := 0)¶ Gets the next checked row after
Start
.Returns: Row number of the next checked row.
-
GetNextFocused
(Start := 0)¶ Gets the next focused row after
Start
.Returns: Row number of the next focused row.
-
GetCount
(Option := "")¶ Calls LV_GetCount(). It is however recommended you use the methods above.
Parameters: Option – What kind of rows to count. Returns: Amount of rows.
-
GetNext
(Start := 0, Option := "")¶ Calls LV_GetNext(). It is however recommended you use the methods above.
Parameters: - Start – Which row to start at when finding the next.
- Option – What kind of row to find.
Returns: Row number of the next checked or focused row.
-
StatusBarControl¶
-
class
GuiBase.
StatusBarControl
¶ This class extends
GuiBase.ControlType
-
Type
¶ The type of control, contains
"StatusBar"
-
SetText
(NewText, PartNumber := 1, Style := "")¶ Calls SB_SetText().
Parameters: - NewText – New text contents.
- PartNumber – Which part to change to
NewText
. - Style – See the documentation link above.
-
SetParts
(Width*)¶ Calls SB_SetParts().
Parameters: Width* – New widths of the parts.
-
SetParts
(File, IconNumber := "", PartNumber := 1) Calls SB_SetIcon().
Parameters: - File – Icon file.
- IconNumber – Icon number of the file.
- PartNumber – Which part to set the icon on.
-
Position types¶
WindowPosition¶
-
class
GuiBase.
WindowPosition
¶ This class extends
GuiBase.PositionType
You can use the properties to set and get position/size of a window.
ControlPosition¶
-
class
GuiBase.
ControlPosition
¶ This class extends
GuiBase.PositionType
You can use the properties to set and get position/size of a control.
Gui events¶
This section contains a list of all Gui events.
These methods are not supposed to be called. For a practical example of how these are used, see Examples.
-
GuiBase.
Close
()¶ Called when the close button is clicked on the Gui.
-
GuiBase.
Escape
()¶ Called when the escape button is pressed while the Gui is focused.
-
GuiBase.
Size
(EventInfo, Width, Height)¶ Called when the Gui is resized.
Parameters: - EventInfo – 0 if resized, 1 if minimized and 2 if maximized.
- Width – The new width of the Gui window.
- Height – The new height of the Gui window.
-
GuiBase.
DropFiles
(FileArray, Control, X, Y)¶ Called when files are dropped onto the Gui.
Parameters: - FileArray – Array of files.
- Control – Which control the files were “dropped” onto.
- X – X coordinate of where the files were dropped.
- Y – Y coordinate.
-
GuiBase.
ContextMenu
(Control, EventInfo, IsRightClick, X, Y)¶ Called when the user right-clicks anywhere in the window except the title or menu bar.
Parameters: - Control – Control which was right-clicked, if any.
- EventInfo –
See the documentation.
- Height – The new height of the Gui window.