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 , Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText
Parameters
- OutputVar
The name of the variable in which to store the result of Cmd.
- Cmd
- See list below.
- 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 is the operation to perform, which if blank defaults to ID. It can be one of the following words:
ID: Retrieves the unique ID number (HWND/handle) of a window. 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: Same as above except it retrieves the ID of the last/bottommost window if there is more than one match. If there is only one match, it performs identically to ID. This concept is similar to that used by WinActivateBottom.
PID: Retrieves the Process ID (PID) of a window.
ProcessName: Retrieves the name of the process (e.g. notepad.exe) that owns a window. If there are no matching windows, OutputVar is made blank.
ProcessPath [v1.1.01+]: Similar to ProcessName, but retrieves the full path and name of the process instead of just the name.
Count: Retrieves the number of existing windows that match the specified WinTitle, WinText, ExcludeTitle, and ExcludeText (0 if none). 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 specified WinTitle, WinText, ExcludeTitle, and 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. 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 names for all controls in a window. 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 the examples section 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.
The control currently under the mouse cursor can be retrieved via MouseGetPos.
ControlListHwnd [v1.0.43.06+]: Same as above except it retrieves the window handle (HWND) of each control rather than its ClassNN.
Transparent: Retrieves the degree of transparency of a window (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 (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 or ExStyle: Retrieves an 8-digit hexadecimal number representing style or extended style (respectively) of a window. 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. ... the window is disabled, so perform appropriate action.
The next 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. ... the window is always-on-top, so perform appropriate action.
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
; Example #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%". ; Example #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 } ; Example #3: Extract the individual control names from a ControlList: WinGet, ActiveControlList, ControlList, A Loop, Parse, ActiveControlList, `n { MsgBox, 4,, Control #%A_Index% is "%A_LoopField%". Continue? IfMsgBox, No break } ; Example #4: Display in real time the active window's control list: #Persistent SetTimer, WatchActiveWindow, 200 return WatchActiveWindow: WinGet, ControlList, ControlList, A ToolTip, %ControlList% return