Control

Makes a variety of changes to a control.

Control, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]

Parameters

Cmd, Value

See list 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.

Cmd, Value

The Cmd and Value parameters are dependent upon each other and their usage is described below.

Check: Turns on (checks) a radio button or checkbox.

Uncheck: Turns off a radio button or checkbox.

Enable: Enables a control if it was previously disabled.

Disable: Disables or "grays out" a control.

Show: Shows a control if it was previously hidden.

Hide: Hides a control. If you additionally want to prevent a control's shortcut key (underlined letter) from working, disable the control via Control Disable.

Style, N or ExStyle, N: Changes the style or extended style of a control, respectively. 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.

ShowDropDown: Drops a ComboBox so that its choices become visible.

HideDropDown: Reverses the above.

TabLeft [, Count] and TabRight [, Count]: Moves left or right by one or more tabs in a SysTabControl32. 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.

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

Delete, N: Deletes the Nth entry from a ListBox or ComboBox. N should be 1 for the first entry, 2 for the second, etc.

Choose, N: Sets the selection in a ListBox or ComboBox to be the Nth entry. 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 these examples:

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

ChooseString, String: Sets the selection (choice) in a ListBox or ComboBox to be the first entry whose leading part matches String. 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, String: Pastes String at the caret/insert position in an Edit control (this does not affect the contents of the clipboard).

ErrorLevel

[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 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.

Related

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

Example

Control, HideDropDown, , ComboBox1, Some Window Title