Control

Makes a variety of changes to a control.

Control, SubCommand , Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Parameters

SubCommand, Value
These are dependent upon each other and their usage is described below.
Control

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. If this parameter is blank, the target window's topmost control will be used.

To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off). The HWND of a control is typically retrieved via ControlGet Hwnd, MouseGetPos, or DllCall().

WinTitle
A window title or other criteria identifying the target window. See WinTitle.
WinText
If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.
ExcludeTitle
Windows whose titles include this value will not be considered.
ExcludeText
Windows whose text include this value will not be considered.

Sub-commands

For SubCommand, specify one of the following:

Check

Turns on (checks) a radio button or checkbox.

Control, Check ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

To ensure correct functionality, this sub-command also sets the input focus to the control.

Uncheck

Turns off a radio button or checkbox.

Control, Uncheck ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

To ensure correct functionality, this sub-command also sets the input focus to the control.

Enable

Enables a control if it was previously disabled.

Control, Enable ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Disable

Disables or "grays out" a control.

Control, Disable ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Show

Shows a control if it was previously hidden.

Control, Show ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Hide

Hides a control.

Control, Hide ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

If you additionally want to prevent a control's shortcut key (underlined letter) from working, disable the control via the Disable sub-command.

Style

Changes the style of a control.

Control, Style, N , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

If the first character of N is a plus or minus sign, the style(s) in N are added or removed, respectively. If the first character is a caret (^), the style(s) in N are each toggled to the opposite state. If the first character is a digit, the control's style is overwritten completely; that is, it becomes N. ErrorLevel is set to 1 if the target window/control is not found or the style is not allowed to be applied.

Certain style changes require that the entire window be redrawn using WinSet Redraw. Also, the styles table lists some of the style numbers. For example:

Control, Style, ^0x800000, Edit1, WinTitle  ; Set the WS_BORDER style to its opposite state.

ExStyle

Changes the extended style of a control.

Control, ExStyle, N , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

See the Style sub-command above for details.

ShowDropDown

Shows the drop-down list of a ComboBox control.

Control, ShowDropDown ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

HideDropDown

Hides the drop-down list of a ComboBox control.

Control, HideDropDown ,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

TabLeft

Moves left by one or more tabs in a SysTabControl32.

Control, TabLeft , Count, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Count is assumed to be 1 if omitted or blank. To instead select a tab directly by number, replace the number 5 below with one less than the tab number you wish to select. In other words, 0 selects the first tab, 1 selects the second, and so on:

SendMessage, 0x1330, 5,, SysTabControl321, WinTitle  ; 0x1330 is TCM_SETCURFOCUS.
Sleep 0  ; This line and the next are necessary only for certain tab controls.
SendMessage, 0x130C, 5,, SysTabControl321, WinTitle  ; 0x130C is TCM_SETCURSEL.

TabRight

Moves right by one or more tabs in a SysTabControl32.

Control, TabRight , Count, Control, WinTitle, WinText, ExcludeTitle, ExcludeText

See the TabLeft sub-command above for details.

Add

Adds String as a new entry at the bottom of a ListBox, ComboBox (and possibly other types).

Control, Add, String , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

Delete

Deletes the Nth entry from a ListBox or ComboBox.

Control, Delete, N , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

N should be 1 for the first entry, 2 for the second, etc.

Choose

Sets the selection in a ListBox or ComboBox to be the Nth entry.

Control, Choose, N , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

N should be 1 for the first entry, 2 for the second, etc. To select or deselect all items in a multi-select listbox, follow this example:

PostMessage, 0x0185, 1, -1, ListBox1, WinTitle  ; Select all listbox items. 0x0185 is LB_SETSEL.

ChooseString

Sets the selection (choice) in a ListBox or ComboBox to be the first entry whose leading part matches String.

Control, ChooseString, String , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

The search is not case sensitive. For example, if a ListBox/ComboBox contains the item "UNIX Text", specifying the word unix (lowercase) would be enough to select it.

EditPaste

Pastes String at the caret/insert position in an Edit control.

Control, EditPaste, String , Control, WinTitle, WinText, ExcludeTitle, ExcludeText

This does not affect the contents of the clipboard.

Error Handling

[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 there was a problem or 0 otherwise.

Remarks

To improve reliability, a delay is done automatically after every use of this command (except for the sub-commands Style and ExStyle). That delay can be changed via SetControlDelay.

To discover the ClassNN or HWND of the control that the mouse is currently hovering over, use MouseGetPos.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

SetControlDelay, ControlGet, GuiControl, ControlGetText, ControlSetText, ControlMove, ControlGetPos, ControlClick, ControlFocus, ControlSend, WinSet

Examples

Hides the drop-down list of the first ComboBox.

Control, HideDropDown,, ComboBox1, Some Window Title