Some applications display sensitive information. With Recall, Windows periodically takes screenshots of your screen and can store that sensitive information.
You can exclude your application from this feature, and from screen capture more generally, by using SetWindowDisplayAffinity with the WDA_EXCLUDEFROMCAPTURE flag. This Windows API function controls how a window interacts with screen capture and recording software.
Add the NuGet package Microsoft.Windows.CsWin32
Add a NativeMethods.txt file to your project with the following content:
NativeMethods.txt
SetWindowDisplayAffinity
Add the following code to your project:
C#
unsafe
{
// WPF: new WindowInteropHelper(Application.Current.MainWindow).Handle
// WinForms: this.Handle
var windowHandle = (HWND)Handle;
Windows.Win32.PInvoke.SetWindowDisplayAffinity(
window,
Windows.Win32.UI.WindowsAndMessaging.WINDOW_DISPLAY_AFFINITY.WDA_EXCLUDEFROMCAPTURE);
}
To test the flag is working, you can use the Snipping Tool or any other screen capture software. If the flag is set correctly, the application window should not be captured.
Note that it is possible to enable and disable the WDA_EXCLUDEFROMCAPTURE flag on demand. So, you can use it to hide sensitive information only when needed.
#Additional resources
Do you have a question or a suggestion about this post? Contact me!