Windows can keep a window out of screen recordings through SetWindowDisplayAffinity, and C# desktop apps can call it with a small P/Invoke wrapper. The post explains the affinity values, the WPF handle step and where the protection stops.
Key points
- `SetWindowDisplayAffinity(hWnd, affinity)` takes a top-level window handle and one of three affinity values.
- `WDA_EXCLUDEFROMCAPTURE` (0x11) removes the window from captures so the content behind it shows.
- It needs Windows 10 version 2004 (build 19041); older builds should fall back to `WDA_MONITOR`.
- `WDA_MONITOR` (0x1) renders the window as a black rectangle inside the capture instead.
- In WPF, read the handle from `new WindowInteropHelper(this).Handle` after `SourceInitialized`.
- It is not DRM: desktop duplication and window capture APIs are blocked, cameras and kernel tools are not.
Why it matters
Anyone shipping a WPF or WinForms app that shares pixels with a recorder — teleprompters, note overlays, kiosk dashboards, support tooling — should know this call exists, because .NET itself offers no managed equivalent. Adoption cost is low: one small P/Invoke class plus a version check, since WDA_EXCLUDEFROMCAPTURE needs Windows 10 2004, so the WDA_MONITOR fallback has to stay for older machines. Two limits shape the design: affinity belongs to the top-level window, so a single control cannot be hidden, and recorder behaviour shifts between versions. Treat it as privacy UX, never a security boundary.
Real-world use
- A teleprompter overlay that sits on the screen being recorded but must never appear in the video.
- Speaker notes shown on a shared screen while attendees see only the slides.
- Sensitive admin panels kept out of a recorded support session or product demo.
This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original