# WinGet

Retrieves the specified window's unique ID, process ID, process name, or a list of its controls. It can also retrieve a list of all windows matching the specified criteria.

    WinGet, OutputVar , SubCommand, WinTitle, WinText, ExcludeTitle, ExcludeText

## Parameters

OutputVar
  The name of the variable in which to store the result of SubCommand.
SubCommand
  The operation to perform, which if blank defaults to the ID sub-command. See Sub-commands.
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:

- ID: Retrieves the unique ID number of a window.
- IDLast: Retrieves the unique ID number of the last/bottommost window if there is more than one match.
- PID: Retrieves the Process ID number of a window.
- ProcessName: Retrieves the name of the process that owns a window.
- ProcessPath [v1.1.01+]: Retrieves the full path and name of the process that owns a window.
- Count: Retrieves the number of existing windows that match the title/text parameters.
- List: Retrieves the unique ID numbers of all existing windows that match the title/text parameters.
- MinMax: Retrieves the minimized/maximized state for a window.
- ControlList: Retrieves the control name for each control in a window.
- ControlListHwnd [v1.0.43.06+]: Retrieves the unique ID number for each control in a window.
- Transparent: Retrieves the degree of transparency of a window.
- TransColor: Retrieves the color that is marked transparent in a window.
- Style: Retrieves an 8-digit hexadecimal number representing the style of a window.
- ExStyle: Retrieves an 8-digit hexadecimal number representing the extended style of a window.

### ID

Retrieves the unique ID number of a window.

    WinGet, OutputVar, ID , WinTitle, WinText, ExcludeTitle, ExcludeText

Also known as the window handle (HWND). If there is no matching window, OutputVar is made blank. The functions WinExist() and WinActive() can also be used to retrieve the ID of a window; for example, `WinExist("A")` is a fast way to get the ID of the active window. To discover the HWND of a control (for use with Post/SendMessage or DllCall), use ControlGet Hwnd or MouseGetPos.

### IDLast

Retrieves the unique ID number of the last/bottommost window if there is more than one match.

    WinGet, OutputVar, IDLast , WinTitle, WinText, ExcludeTitle, ExcludeText

Also known as the window handle (HWND). If there is no matching window, OutputVar is made blank. If there is only one match, it performs identically to the ID sub-command. This concept is similar to that used by WinActivateBottom.

### PID

Retrieves the Process ID number of a window.

    WinGet, OutputVar, PID , WinTitle, WinText, ExcludeTitle, ExcludeText

If there is no matching window, OutputVar is made blank.

### ProcessName

Retrieves the name of the process that owns a window.

    WinGet, OutputVar, ProcessName , WinTitle, WinText, ExcludeTitle, ExcludeText

For example, this would be "notepad.exe". If there are no matching windows, OutputVar is made blank.

### ProcessPath [v1.1.01+]

Retrieves the full path and name of the process that owns a window.

    WinGet, OutputVar, ProcessPath , WinTitle, WinText, ExcludeTitle, ExcludeText

For example, this would be "C:\Windows\System32\notepad.exe". If there are no matching windows, OutputVar is made blank.

### Count

Retrieves the number of existing windows that match the title/text parameters.

    WinGet, OutputVar, Count , WinTitle, WinText, ExcludeTitle, ExcludeText

If there are no matching windows, OutputVar is set to zero. To count all windows on the system, omit all four title/text parameters. Hidden windows are included only if DetectHiddenWindows has been turned on.

### List

Retrieves the unique ID numbers of all existing windows that match the title/text parameters.

    WinGet, OutputVar, List , WinTitle, WinText, ExcludeTitle, ExcludeText

To retrieve all windows on the entire system, omit all four title/text parameters. Each ID number is stored in a variable whose name begins with OutputVar's own name (to form a pseudo-array), while OutputVar itself is set to the number of retrieved items (0 if none). For example, if OutputVar is MyArray and two matching windows are discovered, MyArray1 will be set to the ID of the first window, MyArray2 will be set to the ID of the second window, and MyArray itself will be set to the number 2. Windows are retrieved in order from topmost to bottommost (according to how they are stacked on the desktop). Hidden windows are included only if DetectHiddenWindows has been turned on. Within a function, to create a pseudo-array that is global instead of local, declare MyArray 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.

### MinMax

Retrieves the minimized/maximized state for a window.

    WinGet, OutputVar, MinMax , WinTitle, WinText, ExcludeTitle, ExcludeText

OutputVar is made blank if no matching window exists; otherwise, it is set to one of the following numbers:

- -1: The window is minimized (WinRestore can unminimize it).
- 1: The window is maximized (WinRestore can unmaximize it).
- 0: The window is neither minimized nor maximized.

### ControlList

Retrieves the control name for each control in a window.

    WinGet, OutputVar, ControlList , WinTitle, WinText, ExcludeTitle, ExcludeText

If no matching window exists or there are no controls in the window, OutputVar is made blank. Otherwise, each control name consists of its class name followed immediately by its sequence number (ClassNN), as shown by Window Spy.

Each item except the last is terminated by a linefeed (`n). To examine the individual control names one by one, use a parsing loop as shown in example #3 below.

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.

### ControlListHwnd [v1.0.43.06+]

Retrieves the unique ID number for each control in a window.

    WinGet, OutputVar, ControlListHwnd , WinTitle, WinText, ExcludeTitle, ExcludeText

If no matching window exists or there are no controls in the window, OutputVar is made blank. Otherwise, each unique ID is the window handle (HWND) of the control. Each item except the last is terminated by a linefeed (`n).

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.

### Transparent

Retrieves the degree of transparency of a window.

    WinGet, OutputVar, Transparent , WinTitle, WinText, ExcludeTitle, ExcludeText

See WinSet for how to set transparency. OutputVar is made blank if: 1) the OS is older than Windows XP; 2) there are no matching windows; 3) the window has no transparency level; or 4) other conditions (caused by OS behavior) such as the window having been minimized, restored, and/or resized since it was made transparent. Otherwise, a number between 0 and 255 is stored, where 0 indicates an invisible window and 255 indicates an opaque window. For example:

    MouseGetPos,,, MouseWin
    WinGet, Transparent, Transparent, ahk_id %MouseWin%  ; Transparency of window under the mouse cursor.

### TransColor

Retrieves the color that is marked transparent in a window.

    WinGet, OutputVar, TransColor , WinTitle, WinText, ExcludeTitle, ExcludeText

See WinSet for how to set the TransColor. OutputVar is made blank if: 1) the OS is older than Windows XP; 2) there are no matching windows; 3) the window has no transparent color; or 4) other conditions (caused by OS behavior) such as the window having been minimized, restored, and/or resized since it was made transparent. Otherwise, a six-digit hexadecimal RGB color is stored, e.g. 0x00CC99. For example:

    MouseGetPos,,, MouseWin
    WinGet, TransColor, TransColor, ahk_id %MouseWin%  ; TransColor of the window under the mouse cursor.

### Style

Retrieves an 8-digit hexadecimal number representing the style of a window.

    WinGet, OutputVar, Style , WinTitle, WinText, ExcludeTitle, ExcludeText

If there are no matching windows, OutputVar is made blank. The following example determines whether a window has the WS_DISABLED style:

    WinGet, Style, Style, My Window Title
    if (Style & 0x8000000)  ; 0x8000000 is WS_DISABLED.
      MsgBox The window is disabled.

See the styles table for a partial listing of styles.

### ExStyle

Retrieves an 8-digit hexadecimal number representing the extended style of a window.

    WinGet, OutputVar, ExStyle , WinTitle, WinText, ExcludeTitle, ExcludeText

If there are no matching windows, OutputVar is made blank. The following example determines whether a window has the WS_EX_TOPMOST style (always-on-top):

    WinGet, ExStyle, ExStyle, My Window Title
    if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.
       MsgBox The window is always-on-top.

See the styles table for a partial listing of styles.

## Remarks

A window's ID number is valid only during its lifetime. In other words, if an application restarts, all of its windows will get new ID numbers.

ID numbers retrieved by this command are numeric (the prefix "ahk_id" is not included) and are stored in hexadecimal format regardless of the setting of SetFormat.

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

Although ID numbers are currently 32-bit unsigned integers, they may become 64-bit in future versions. Therefore, it is unsafe to perform numerical operations such as addition on these values because such operations require that their input strings be parsable as signed rather than unsigned integers.

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

## Related

WinGetClass, Process, WinGetTitle, MouseGetPos, ControlGet, ControlFocus, GroupAdd

## Examples

#1: Maximize the active window and report its unique ID:

    WinGet, active_id, ID, A
    WinMaximize, ahk_id %active_id%
    MsgBox, The active window's ID is "%active_id%".

#2: This will visit all windows on the entire system and display info about each of them:

    WinGet, id, List,,, Program Manager
    Loop, %id%
    {
        this_id := id%A_Index%
        WinActivate, ahk_id %this_id%
        WinGetClass, this_class, ahk_id %this_id%
        WinGetTitle, this_title, ahk_id %this_id%
        MsgBox, 4, , Visiting All Windows`n%A_Index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
        IfMsgBox, NO, break
    }

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

    WinGet, ActiveControlList, ControlList, A
    Loop, Parse, ActiveControlList, `n
    {
        MsgBox, 4,, Control #%A_Index% is "%A_LoopField%". Continue?
        IfMsgBox, No
            break
    }

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

    #Persistent
    SetTimer, WatchActiveWindow, 200
    return

    WatchActiveWindow:
    WinGet, ControlList, ControlList, A
    ToolTip, %ControlList%
    return