GuiControlGet

Retrieves various types of information about a control in a GUI window.

GuiControlGet, OutputVar [, Sub-command, ControlID, Param4]

 

Parameters

OutputVar The name of the variable in which to store the result. If the command cannot complete (see ErrorLevel below), this variable is made blank.
Sub-command See list below.
ControlID

If blank or omitted, it defaults to the control whose associated output variable is OutputVar.

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 name/text of the control, both of which can be determined via Window Spy. When using name/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.

Param4 This parameter is omitted except where noted in the list of sub-commands below.

 

ErrorLevel

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.

 

Sub-commands

(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: 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: ^!C, ^Home, +^NumpadHome.

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: ListViews are not supported when Sub-command is blank. Instead, use the built-in ListView functions.

Note: To unconditionally retrieve any control's text/caption rather than its contents, specify the word Text for Param4.


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 an set of variables that is global instead of local, declare OutputVar as a global variable prior to using this command.


Focus
: Retrieves the control identifier (ClassName+NN) 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. For example: ControlGet, focused_control, focus

Enabled: Retrieves 1 if the control is enabled or 0 if it is disabled.

Visible: Retrieves 1 if the control is visible or 0 if it is hidden.

 

Remarks

To operate upon a window number other than the default (see below), include a number followed by a colon in front of the sub-command as in these examples:
GuiControlGet, MyEdit, 2:
GuiControlGet, MyEdit, 2:Pos
GuiControlGet, Outputvar, 2:Focus

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 number for a GUI thread is that of the window that launched the thread. Non-GUI threads use 1 as their default.

 

Related

Gui, GuiControl, ControlGet

 

Examples

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