The API: SetWindowDisplayAffinity
Since Windows 10 version 2004, SetWindowDisplayAffinity accepts the flag WDA_EXCLUDEFROMCAPTURE (0x11). A window with that affinity is still drawn on the monitor, but the desktop compositor leaves it out of any picture of the screen it hands to software, showing what's behind it instead.
Because the exclusion happens in the compositor, every capture method that goes through Windows gets the same result: screen sharing in Zoom, Teams and Webex, browser screen sharing in Meet, OBS, the Snipping Tool and Print Screen. Before version 2004 the only option was WDA_MONITOR, which shows a black rectangle in captures instead of hiding the window.
In code
A window can only set its own affinity, from the process that owns it. In C#:
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowDisplayAffinity(IntPtr hWnd, uint affinity);
const uint WDA_NONE = 0x00;
const uint WDA_MONITOR = 0x01;
const uint WDA_EXCLUDEFROMCAPTURE = 0x11;
// After the window has a handle (WPF: in SourceInitialized).
var hwnd = new WindowInteropHelper(window).Handle;
if (!SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE))
SetWindowDisplayAffinity(hwnd, WDA_MONITOR); // older Windows: black box instead
GetWindowDisplayAffinity reads the current value back, which is useful for checking that it took.
The part most apps miss: pop-ups and menus
Affinity is per window, and in Windows a tooltip, a context menu, a combo box's drop-down and a file dialog are each separate top-level windows. Shield only the main window and a tooltip appearing over it will show up in the share.
The fix that holds is to shield every top-level window your UI thread creates, as it's created. Peekaboo installs a thread-level window hook (WH_CALLWNDPROCRET) and sets the affinity on WM_CREATE, before the window is ever shown, so there's no frame in which it could be captured.
Testing it
Don't trust it until you've measured it. A simple automated test:
- Show a solid-colour window (say pure green) as a backdrop.
- Show your shielded window over it.
- Capture the area with each method: GDI
BitBlt, DXGI Desktop Duplication and Windows.Graphics.Capture. - Count the backdrop-coloured pixels inside your window's rectangle. Shielded, nearly all of them should be green; unshielded, almost none.
Run the unshielded case too, so you know the measurement can fail. Peekaboo runs exactly this on every build, for the overlay, the dashboard, menus and tooltips, and for the shipped app with a real answer on screen.
Limits
- It doesn't affect cameras, people in the room or hardware that captures the video signal.
- It doesn't hide that the app is running; the process and its taskbar entry (unless removed) are still there.
- It needs the desktop compositor, which is always on in Windows 10 and 11.
See it in practice on our invisible on screen share page, with real captures of the same moment taken both ways.