Microsoft has been developed an API named SetWindowDisplayAffinity to support the window content protection. This feature enables applications to protect application content from being captured or copied through a specific set of public operating system features and APIs. Unlike other security features or an implementation of DRM there is no guarantee that this API can strictly protect window content, for example where someone takes a photograph of screen using mobile camera. But this API is feasible and easy to use.
BOOL SetWindowDisplayAffinity(HWND hWnd,DWORD dwAffinity);
There are two types of DWORD values WDA_MONITOR and WDA_NONE. We have to set WDA_MONITOR to protect the application contents.
It's basically C++ API but we can use this for other windows C# application like Winform or WPF by extern the C++ API's. (Sample code C#)
using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsAppPrtScrProtector { public partial class Form1 : Form { const uint WDA_NONE = 0; const uint WDA_MONITOR = 1; [DllImport("user32.dll")] public static extern uint SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SetWindowDisplayAffinity(this.Handle, WDA_MONITOR); } } }
Note:
For WPF you have to create Handler by your self for SetWindowDisplayAffinity's first
parameter like bellow:
For WPF you have to create Handler by your self for SetWindowDisplayAffinity's first
parameter like bellow:
private void ContentControl_Loaded(object sender, RoutedEventArgs e){ IntPtr hwnd = new WindowInteropHelper(this).Handle; SetWindowDisplayAffinity(hwnd, WDA_MONITOR); }
We can use this API with C++ application easily. Here bellow is the code: (Sample code C++)
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // Store instance handle in our global variable HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { return FALSE; } SetWindowDisplayAffinity(hWnd, WDA_MONITOR); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
Happy coding. :)
Looks like C, not C++.
ReplyDeleteIts Not C or C++. Its c# (csharp).
DeleteHow To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download Now
Delete>>>>> Download Full
How To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download LINK
>>>>> Download Now
How To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download Full
>>>>> Download LINK gm
I am getting the access denied error in SetWindowDisplayAffinity
ReplyDeleteI am getting the access denied error in SetWindowDisplayAffinity
ReplyDeleteDownload the sample code or post your code here to observe the error details.
DeleteHi thank you for your post. I can prevent user to capture my Content from WPF media element tools. But the sound Still capture.
ReplyDeleteHow can I Detect the SetWindowDisplayAffinity? So when this function is execute my player stop working to and show the message to user close that program if they want use my app?
SetWindowDisplayAffinity(https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity) will make sure to capture the screen of the application. As almost every screen recorder capture the image, then makes it dynamic. So it will make sure to protect the screen not the audio portion. If you want to protect your audio also then make it complex by hardware rendering and HDCP(https://en.wikipedia.org/wiki/High-bandwidth_Digital_Content_Protection) for your output.
DeleteYou can also check Microsoft's latest API "PlayReady DRM"(https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/playready-client-sdk) which is available for UWP but as we know there is a way to use WINRT API in WPF. So you can try this out.
thank you I test it and write here the result. But I have question are this API Only Support win 10 or Support the another version of windows too?
DeleteMinimum supported client: Windows 7 [desktop apps only]
DeleteMinimum supported server :Windows Server 2008 R2 [desktop apps only]
I have test with window 7 but it's not works.
ReplyDeleteCan you please guide me why screen capture not prevent in window 7.
ReplyDeletePlease download the sample project and run in your PC and let me know the result.
Deletecan u tell me how to overcome this as a user ?
ReplyDeletethank you alot, works just fine with windows 10.
ReplyDeleteHow do i make it transparent Like it just doesnt show at all in recording
ReplyDeleteHow To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download Now
ReplyDelete>>>>> Download Full
How To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download LINK
>>>>> Download Now
How To Prevent/Disable/Protect Screen Capture Of Windows Application (Winform,Wpf,Win32,Mfc Etc.) - Yeasir007 >>>>> Download Full
>>>>> Download LINK x8