Windows 7 (shipping since July 2009) introduced the SetWindowDisplayAffinity()
API. Setting the affinity for a window to a value of WDA_MONITOR
has the effect1 of blanking out the window contents whenever it is captured. The setting is honored regardless of whether the capture is performed via a BitBlt()
call or the newer screen capture API.
SetWindowDisplayAffinity()
is available for desktop applications only. For UWP applications the corresponding functionality is exposed through the ApplicationView.IsScreenCaptureEnabled
property.
The intended purpose of this API is to protect against accidental information disclosure. It is not to be confused with a security feature2.
Windows 10 2004 (Build 19041) extended the API with the WDA_EXCLUDEFROMCAPTURE
affinity value. In contrast to WDA_MONITOR
(which leaves a blanked-out window in a screen capture), this setting removes the window entirely. Whatever is behind this window will show up in a screen capture instead.
The designated use case is to allow screen recording software to show a control GUI without it occluding part of the recording.
1 This requires that desktop composition is enabled. Starting with Windows 8 desktop composition can no longer be disabled.
2 How do I make it more difficult for somebody to take a screenshot of my window?