IfWinExist / IfWinNotExist

Checks if the specified window exists.

Deprecated: These control flow statements are not recommended for use in new scripts. Use the WinExist function instead.

IfWinExist , WinTitle, WinText, ExcludeTitle, ExcludeText
IfWinNotExist , WinTitle, WinText, ExcludeTitle, ExcludeText

Parameters

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. Note: Due to backward compatibility, this parameter will be interpreted as a command if it exactly matches the name of a command. To work around this, use the WinExist function instead.
ExcludeText
Windows whose text include this value will not be considered.

Remarks

If all parameters are omitted, the Last Found Window will be checked to see if it still exists (or doesn't exist in the case of IfWinNotExist).

If either of these control flow statements determines that a qualified window exists, the Last Found Window will be updated to be that window. In other words, if IfWinExist evaluates to true or IfWinNotExist evaluates to false, the Last Found Window will be updated.

To discover the HWND of a control (for use with Post/SendMessage or DllCall), use ControlGet Hwnd or MouseGetPos.

SetWinDelay does not apply to these control flow statements.

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

WinExist(), WinActive(), SetTitleMatchMode, DetectHiddenWindows, Last Found Window, Process, WinActivate, WinWaitActive, WinWait, WinWaitClose, #IfWinActive/Exist

Examples

Activates and maximizes the Notepad window found by the IfWinExist statement above.

IfWinExist, Untitled - Notepad
{
    WinActivate ; Use the window found by IfWinExist.
    WinMaximize ; Same as above.
    Send, Some text.{Enter}
    return
}

Returns if the calculator does not exist, otherwise it will be activated and moved to a new position.

IfWinNotExist, Calculator
    return
else
{
    WinActivate ; Use the window found by IfWinNotExist.
    WinMove, 40, 40 ; Same as above.
    return
}