SetWindowDisplayAffinity function (winuser.h)
Specifies where the content of the window can be displayed.
Syntax
BOOL SetWindowDisplayAffinity(
[in] HWND hWnd,
[in] DWORD dwAffinity
);
Parameters
[in] hWnd
Type: HWND
A handle to the top-level window. The window must belong to the current process.
[in] dwAffinity
Type: DWORD
The display affinity setting that specifies where the content of the window can be displayed.
This parameter can be one of the following values.
Return value
Type: BOOL
If the function succeeds, it returns TRUE; otherwise, it returns FALSE when, for example, the function call is made on a non top-level window. To get extended error information, call GetLastError.
Remarks
This function and GetWindowDisplayAffinity are designed to support the window content protection feature that is new to Windows 7. This feature enables applications to protect their own onscreen window content from being captured or copied through a specific set of public operating system features and APIs. However, it works only when the Desktop Window Manager(DWM) is composing the desktop.
It is important to note that unlike a security feature or an implementation of Digital Rights Management (DRM), there is no guarantee that using SetWindowDisplayAffinity and GetWindowDisplayAffinity, and other necessary functions such as DwmIsCompositionEnabled, will strictly protect windowed content, for example where someone takes a photograph of the screen.
Starting in Windows 10 Version 2004, WDA_EXCLUDEFROMCAPTURE is a supported value. Setting the display affinity to WDA_EXCLUDEFROMCAPTURE on previous version of Windows will behave as if WDA_MONITOR is applied.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 7 [desktop apps only] |
Minimum supported server | Windows Server 2008 R2 [desktop apps only] |
Target Platform | Windows |
Header | winuser.h (include Windows.h) |
Library | User32.lib |
DLL | User32.dll |
API set | ext-ms-win-ntuser-window-l1-1-1 (introduced in Windows 8.1) |