Retrieves various types of information about a control in a GUI window.
GuiControlGet, OutputVar , Sub-command, ControlID, Param4
The name of the variable in which to store the result. If the command cannot complete (see ErrorLevel below), this variable is made blank.
See list below.
If blank or omitted, it behaves as though the name of the output variable was specified. For example,
GuiControlGet, MyEdit is the same as
GuiControlGet, MyEdit,, MyEdit.
If the target control has an associated variable, specify the variable's name as the ControlID (this method takes precedence over the ones described next). For this reason, it is usually best to assign a variable to any control that will later be accessed via GuiControl or GuiControlGet, even if that control is not input-capable (such as GroupBox or Text).
Otherwise, ControlID can be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy. When using text, the matching behavior is determined by SetTitleMatchMode.
Note: A picture control's file name (as it was specified at the time the control was created) may be used as its ControlID.
[v1.1.04+]: ControlID can be the HWND of a control.
If the control is not on the default GUI, the name of the GUI must also be specified -- except on [v1.1.20+] when ControlID is a HWND, since each HWND is unique. See Remarks for details.
This parameter is omitted except where noted in the list of sub-commands below.
[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.
ErrorLevel is set to 1 if the specified window/control does not exist or some other problem prevented the command from working. Otherwise, it is set to 0.
(Blank): Leave Sub-command blank to retrieve the control's contents. All control types are self-explanatory except the following:
Picture: Retrieves the picture's file name as it was originally specified when the control was created. This name does not change even if a new picture file name is specified.
Edit: Retrieves the contents but any line breaks in the text will be represented as plain linefeeds (`n) rather than the traditional CR+LF (`r`n) used by non-GUI commands such as ControlGetText and ControlSetText.
Hotkey: Retrieves a blank value if there is no hotkey in the control. Otherwise it retrieves the modifiers and key name. Examples:
Checkbox/Radio: Retrieves 1 if the control is checked, 0 if it is unchecked, or -1 if it has a gray checkmark. To retrieve the control's text/caption instead, specify the word Text for Param4. Note: Unlike the Gui Submit command, radio buttons are always retrieved individually, regardless of whether they are in a radio group.
UpDown/Slider/Progress: Retrieves the control's current position.
Tab/DropDownList/ComboBox/ListBox: Retrieves the text of the currently selected item/tab (or its position if the control has the AltSubmit property). For a ComboBox, if there is no selected item, the text in the control's edit field is retrieved instead. For a multi-select ListBox, the output uses the window's current delimiter.
ListView and TreeView: These are not supported when Sub-command is blank. Instead, use the built-in ListView functions and TreeView functions.
StatusBar: Retrieves only the first part's text.
ActiveX: Retrieves a new wrapper object for the control's ActiveX component.
Note: To unconditionally retrieve the text/caption of a CheckBox, Radio, DropDownList or ComboBox rather than its contents, specify the word Text for Param4.
GuiControlGet, OutputVar, Pos: Retrieves the position and size of the control. The position is relative to the GUI window's client area, which is the area not including title bar, menu bar, and borders. The information is stored in four variables whose names all start with OutputVar. For example:
GuiControlGet, MyEdit, Pos MsgBox The X coordinate is %MyEditX%. The Y coordinate is %MyEditY%. The width is %MyEditW%. The height is %MyEditH%.
Within a function, to create a set of variables that is global instead of local, declare OutputVar as a global variable prior to using this command (the converse is true for assume-global functions). However, it is often also necessary to declare each variable in the set, due to a common source of confusion.
GuiControlGet, OutputVar, Focus: Retrieves the control identifier (ClassNN) for the control that currently has keyboard focus. Since the specified GUI window must be active for one of its controls to have focus, OutputVar will be made blank if it is not active. Example usage:
GuiControlGet, focused_control, focus.
GuiControlGet, OutputVar, FocusV [v1.0.43.06+]: Same as Focus (above) except that it retrieves the name of the focused control's associated variable. If that control lacks an associated variable, the first 63 characters of the control's text/caption is retrieved instead (this is most often used to avoid giving each button a variable name).
GuiControlGet, OutputVar, Enabled: Retrieves 1 if the control is enabled or 0 if it is disabled.
GuiControlGet, OutputVar, Visible: Retrieves 1 if the control is visible or 0 if it is hidden.
GuiControlGet, OutputVar, Hwnd [v22.214.171.124+]: Retrieves the window handle (HWND) of the control. A control's HWND is often used with PostMessage, SendMessage, and DllCall. Note: HwndOutputVar is usually a more concise way to get the HWND.
GuiControlGet, OutputVar, Name [v1.1.03+]: Retrieves the name of the control's associated variable if it has one, otherwise OutputVar is made blank.
To operate upon a window other than the default (see below), include its name or number followed by a colon in front of the sub-command as in these examples:
GuiControlGet, MyEdit, MyGui: GuiControlGet, MyEdit, MyGui:Pos GuiControlGet, OutputVar, MyGui:Focus
This is required even if ControlID is a control's associated variable, since any one variable can be used on multiple GUI windows. In [v1.1.20+], the GUI name can be omitted if ControlID is a control's HWND.
A GUI thread is defined as any thread launched as a result of a GUI action. GUI actions include selecting an item from a GUI window's menu bar, or triggering one of its g-labels (such as by pressing a button).
The default window name for a GUI thread is that of the window that launched the thread. Non-GUI threads use 1 as their default.
Gui, GuiControl, ControlGet
GuiControlGet, MyEdit GuiControlGet, CtrlContents,, MyEdit ; Same as the above except uses a non-default output variable. GuiControlGet, MyCheckbox1 ; Retrieves 1 if it is checked, 0 if it is unchecked. GuiControlGet, MyCheckbox1,,, Text ; Retrieves the caption/text of the checkbox. GuiControlGet, Pic, Pos, Static4 ; The position/size will be stored in PicX, PicY, PicW, and PicH