WinGetControls

Returns the control names for all controls in the specified window.

Controls := WinGetControls(WinTitle, WinText, ExcludeTitle, ExcludeText)

Parameters

WinTitle

Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.

WinText

Type: String

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

Type: String

Windows whose titles include this value will not be considered.

ExcludeText

Type: String

Windows whose text include this value will not be considered.

Return Value

Type: Array

This function returns an array containing the control names for all controls in the specified window. Each name of a control consists of its class name followed immediately by its sequence number (ClassNN), as shown by Window Spy. If there is no matching window, an empty string is returned.

For example, if the return value is assigned to a variable named Controls and two controls are present, Controls[1] contains the name of the first control, Controls[2] contains the name of the second control, and Controls.Length returns the number 2.

Controls are sorted according to their Z-order, which is usually the same order as the navigation order via Tab key if the window supports tabbing.

Error Handling

An exception is thrown if the window could not be found or there was an error retrieving the names of its controls.

Remarks

The ID of the window or control under the mouse cursor can be retrieved with MouseGetPos.

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

Related

WinGetControlsHwnd, Win functions, Control functions

Examples

#1: Extract the individual control names from the active window's control list:

for n, ctrl in WinGetControls("A")
{
    Result := MsgBox("Control #" n " is '" ctrl "'. Continue?",, 4)
    if (Result = "No")
        break
}

#2: Display in real time the active window's control list:

SetTimer "WatchActiveWindow", 200

WatchActiveWindow()
{
    try
    {
        Controls := WinGetControls("A")
        ControlList := ""
        for ClassNN in Controls
            ControlList .= ClassNN . "`n"
        if (ControlList = "")
            ToolTip "The active window has no controls."
        else
            ToolTip ControlList
    }
    catch
        ToolTip "No visible window is active."
}