Per-Monitor V2 DPI Coordinate Metrology for Reliable Windows UIA Automation

Automated desktop and browser tests frequently work at 100% scaling (96 DPI) and miss controls by 40 to 150 pixels the moment a user runs a primary display at 125% (120 DPI), 150% (144 DPI), or spans an external monitor. The root cause is mixing logical CSS pixels (window.devicePixelRatio), DPI-virtualized Win32 client coordinates, and physical screen coordinates reported by UI Automation (UIA).

1. Declare Per-Monitor V2 Context Before Window Creation

Every native Windows automation probe or desktop shell (ZeroToCodeLab.exe and UiaDpiVerifier.exe) must call SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) before allocating HWNDs or message loops. Without Per-Monitor V2, Windows bitmap-scales UIA bounding rectangles transparently and returns stale coordinates relative to system DPI.

2. Exact Logical-to-Physical Projection

Inside a Chromium/Edge or WebView2 client area (Chrome Legacy Window / Chrome_WidgetWin_1):

3. Non-Intrusive Background Verification

Launching Playwright/CDP automation on an isolated port (127.0.0.1:9222) inside a dedicated minimized profile preserves the operator's active foreground window (GetForegroundWindow() unchanged) while still allowing UIA accessibility inspection and hardware-accelerated WebView2 telemetry.

Experiment interactively with multi-monitor DPI transitions and axis-aligned bounding-box hit parity here: https://nahianakhtar.github.io/demos/uia-metrology/.