Not able to disable screen capture in WPF using SetWindowDisplayAffinity
Vardan Balyan
10
Reputation points
Hi i have a WPF application based on .NET 6 and i want to disable the screen capture for my app and found SetWindowDisplayAffinity but this code is not working in my project. If i debug my code by getting the last error from Marshal.GetLastWin32Error() then it returns value 87 (ERROR_INVALID_PARAMETER).
What am i doing wrong here? Or am i missing something important?
Thanks
Here is my code for reference :
[DllImport("User32.dll", SetLastError = true)]
private static extern bool SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);
public const int WDA_NONE = 0x00000000;
public const int WDA_MONITOR = 0x00000001;
public const int WDA_EXCLUDEFROMCAPTURE = 0x00000011;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SetWindowDisplayAffinity(new WindowInteropHelper(this).Handle, WDA_MONITOR);
var res = Marshal.GetLastWin32Error();
}
Developer technologies | Windows Presentation Foundation
2,859 questions
Windows development | Windows API - Win32
2,792 questions
Developer technologies | C#
11,582 questions
Sign in to answer