Here's a concise guide to checking windows using AutoHotkey:
Checking Window Existence and State
- `WinExist("Title", "Text")`: Checks if a window exists based on its title and/or text. Returns the unique ID (HWND) of the first matching window, or 0 if no match is found.
- `If WinExist("Title")`: A simple way to check if a window with a specific title exists.
- `WinActive("Title", "Text")`: Checks if a window is currently active (has focus). Returns 1 if active, 0 otherwise.
- `WinNotActive("Title", "Text")`: Checks if a window is not active. Returns 1 if not active, 0 otherwise.
- `WinGetState, OutputVar, Title, Text`: Retrieves the state of a window. `OutputVar` will be 1 if the window exists, 0 if it doesn't.
Checking Window Properties
- `WinGetTitle, OutputVar, Title, Text`: Retrieves the title of a window.
- `WinGetClass, OutputVar, Title, Text`: Retrieves the class name of a window.
- `WinGetText, OutputVar, Title, Text`: Retrieves the text content of a window. Be aware this can be slow for large windows.
- `WinGetPos, X, Y, Width, Height, Title, Text`: Retrieves the position and size of a window.
- `WinGet, OutputVar, ID, Title, Text`: Retrieves the unique ID (HWND) of the window. This is useful for subsequent operations on the same window.
- `WinGet, OutputVar, ProcessName, Title, Text`: Retrieves the name of the process that owns the window.
Example Usage
Here's a basic example:

; Check if Notepad is running
If WinExist("ahk_class Notepad")
{
; Notepad exists
WinActivate ;Activates the window that was found by WinExist automatically.

MsgBox, Notepad is running!
}
Else
{
; Notepad does not exist

MsgBox, Notepad is not running.
Using `ahk_class` and `ahk_exe`
- `ahk_class WindowClassName`: Targets windows based on their class name. This is more reliable than just the title, especially if the title might change.
- `ahk_exe *`: Targets windows based on the executable that created them.
Important Considerations
- Title Matching: The `Title` parameter in most `Win` commands can be a partial match. Use `SetTitleMatchMode` to control how titles are matched (e.g., `SetTitleMatchMode, 2` for "contains" matching).
- Hidden Windows: Some `Win` commands can also operate on hidden windows. Check the specific command documentation for details.