AI Windows: Window Handles
AI-first map of window handles, selectors, matchers, and providers.
Window Handles / Matching / Tracking Discovery Map
Reference map for native window handles, raw HWND conversion, window
enumeration, matching, foreground tracking, and bounds tracking.
Interactive picking belongs to osd/selection.md.
User Intents
- Convert raw
HWND/IntPtrintoIWindowHandle. - Read process id, title, bounds, owner, parent, and visibility for a window.
- Enumerate known windows.
- Match windows by title, process, path, handle, or expression.
- Keep live target-window selection.
- Track foreground window or bounds changes.
Concept Model
IWindowHandleis the PoeShared wrapper around a native window.IWindowHandleProviderconverts raw handles into wrappers.IWindowListProviderowns live enumeration, ignored windows, blacklists, and foreground resolution.IWindowMatcherperforms stateless expression matching.IWindowSelectorkeeps a stateful active target from a match expression.IWindowHandleMatcherandIComplexWindowHandleMatcherare infrastructure include/exclude predicates.- Foreground and bounds trackers wrap native event hooks.
API Details
-
PoeShared.Native.IWindowHandle- Use
Handleonly when rawIntPtris required. - Prefer
ProcessId,ProcessName,Title,Bounds, owner/parent/state metadata over re-querying Win32.
- Use
-
PoeShared.Native.IWindowHandleProviderGetByWindowHandle(IntPtr hwnd)converts raw handles.GetMonitorByWindowHandle(IntPtr hwnd)resolves monitor context.- Does not select or enumerate windows.
-
IWindowListProviderAllWindowList,WindowList,IgnoredWindows,BlacklistedWindows.ResolveByHandle(IntPtr),GetForegroundWindow(),RefreshWindowList().
-
IWindowMatcherIsMatch(...)andFindMatches(...)forWindowMatchExpression.
-
IWindowSelectorTargetWindow,ActiveWindow,MatchingWindowList,OnlyVisible,WindowFilter.- Use when code needs a persistent selected target window that follows a match expression.
-
WindowSelectorExtensionsFindWindow(...)setsTargetWindowand returns the selectedActiveWindow, ornullwhen no match exists.GetWindow(...)setsTargetWindowand returns the selectedActiveWindow; use it when absence is exceptional.- Use
TargetWindowplusActiveWindowwhen absence is expected and should be handled without exceptions and the code wants persistent selector state. - Use
IWindowMatcher.FindMatches(...)when the code intentionally needs multiple matches or matching over a supplied list.
-
WindowHandleExtensionsActivate(...)brings anIWindowHandleto the foreground.Activate(...)delegates toUnsafeNative.ActivateWindow(...).ToWindowMatchExpressionOrDefault(...)creates a reusable match expression from a known window handle.
-
UnsafeNative.ActivateWindow(...)- Low-level activation helper with
IntPtr,IWindowHandle, timeout, and log overloads. - Restores minimized windows before activation and waits for the foreground switch.
- Throws when the target does not become foreground before the timeout.
- Prefer
WindowHandleExtensions.Activate(...)in script/docs examples.
- Low-level activation helper with
-
IForegroundWindowTracker,IWindowTracker- Foreground/active window tracking.
-
IWindowBoundsTrackerFactory- Tracks window rectangle changes.
Common Flows
-
Raw handle to wrapper:
- receive
IntPtr hwnd. - call
IWindowHandleProvider.GetByWindowHandle(hwnd). - pass
IWindowHandledownstream.
- receive
-
Persistent target selection:
- receive
IWindowSelector. - set
TargetWindow. - read
ActiveWindowandMatchingWindowList.
- receive
-
Single target lookup:
- receive
IWindowSelector. - call
FindWindow(...)when absence is expected and should be handled without exception. - call
GetWindow(...)only when absence is exceptional. - use
TargetWindowplusActiveWindowwhen the code wants persistent selector state. - keep the returned
IWindowHandleinstead of re-querying by raw handle or string.
- receive
-
Multiple-match or stateless query:
- receive
IWindowListProviderandIWindowMatcher. - read
WindowsProvider.WindowList.Items. - call
IWindowMatcher.FindMatches(..., targetExpression).
- receive
-
One-shot "window is active" query:
- receive
IWindowListProviderandIWindowMatcher. - call
IWindowListProvider.GetForegroundWindow(). - call
IWindowMatcher.IsMatch(foregroundWindow, targetExpression).
- receive
-
Activate a matched window:
- receive
IWindowSelector. - call
FindWindow(...)when the missing-window path should be handled explicitly. - call
GetWindow(...)only when absence is exceptional. - call
Activate(...)on the handle.
- receive
-
Window match expression basics:
- plain text matches process path, process name, or title.
- quoted text is strict.
/pattern/is regex.0x...or&H...matches a native handle.#2selects the second matching window.&&and||combine simpler expressions.- properties such as
[type=toplevel],[type=child],[visible], and[focus]further constrain matching.
-
Track bounds:
- receive
IWindowBoundsTrackerFactory. - call
Track(window). - dispose the subscription with the owner lifetime.
- receive
Prefer
- Prefer
IWindowHandleafter selection/resolution. - Prefer
IWindowHandleProvideronly for raw handle conversion. - Prefer
IWindowSelectorfor live target matching. - Prefer
IWindowSelector.FindWindow(...)for non-throwing single-window lookup. - Prefer
IWindowSelector.GetWindow(...)only when absence is exceptional. - Prefer
IWindowMatcherplusIWindowListProviderfor multi-window matching, custom supplied lists, or active-window checks that should not mutate selector state. - Prefer direct window-handle APIs for thin window operations.
- Prefer trackers over raw native event hooks.
Avoid
- Avoid storing raw
IntPtras long-term contract. - Avoid using
IWindowHandleProvideras selector/enumerator. - Avoid using aura Actions, Triggers, or Overlays as lightweight wrappers for thin script/API operations. They are stateful Aura Tree runtime objects with configuration and lifecycle.
- Avoid copying AutoHotkey
WinTitletokens such asahk_exeorahk_classdirectly intoWindowMatchExpression; map them deliberately. - Avoid treating activation as guaranteed; foreground activation can time out or be blocked by Windows.
- Avoid direct low-level WinEvent code when trackers exist.
Research Anchors
IWindowHandle,IWindowHandleProvider,IWindowListProvider,IWindowMatcher,IWindowSelector,WindowMatchExpression,WindowSelectorExtensions,WindowHandleExtensions,UnsafeNative.ActivateWindow,IWindowHandleMatcher,IComplexWindowHandleMatcher,IForegroundWindowTracker,IWindowBoundsTrackerFactory,IWinEventHookWrapper.
Search Synonyms
- HWND
- IntPtr window handle
- window handle wrapper
- window selector
- window matcher
- foreground window
- active window
- target window
- window exists
- WinExist
- WinActive
- WinActivate
- window bounds tracker
- WinEvent hook
Related Maps
osd/selection.mdosd/screen-overlay.mdwindows-subsystems/input-hooks-hotkeys.mdmemory/processes.md