how to disable “PRINT SCREEN” button while running my Application in WPF?

倖福魔咒の 提交于 2019-11-29 10:22:56
George Stocker

It's not possible to disable printing, and even if it were possible, it would be easily circumvented by a cell phone camera. Many are in the megapixel resolution range, making it quite easy for someone to get the information they want.

If you want to disable the Print Screen Key on your keyboard, Jodrell's answer gives a way of doing that (understanding that it's not going to keep people from printing, and a determined user will find a way around that).

Really, it all comes down to trust. If an employer can't trust their employees not to remove data that is already protected by law in most jurisdictions (HIPAA in the USA), then there's a bigger issue at stake.

Okay, it is possible, and could indeed be useful if your application is deployed in an environment where a camera is not available to the user.

First of all, I used the RegisterHotKey and UnregisterHotKey API calls, documented here http://pinvoke.net/default.aspx/user32.RegisterHotKey as described in this rather old article here http://msdn.microsoft.com/en-us/magazine/cc163713.aspx.

I registered the IDHOT_SNAPDESKTOP hotkey in the Window_Load event and unregistered it in the Window_Closed. Trying to do this in the constructor gave me problems getting a consistent handle with the WindowInteropHelper(this) method.

If you'd like to do more than just ignore the keys you can set up a windows message handler, making a kind of WndProc using,

HwndSource source = HwndSource.FromHwnd(<handle>);
source.AddHook(<WndProc>);

making the handle as described above, and the WndProc implementation yourself.

As yet, I don't know how to "not" handle the hot key and get windows to perform its normal behaviour except, of course, by unregistering the hotkeys.

Its not very elegant or "WPF" but it worked for me.


As @ghord comments

The use of EnsureHandle() looks useful for getting a handler in the constructor.

Easy:

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;

Simply speaking, you cannot. "Print screen" just copies the pixels on the screen to the clipboard, and is not part of your application.

Aliostad

Basically you can hook to the ClipBoard events and then set the image copied to null if someone does it. So they can copy the image but it will be reset:

Have a look at this:

Clipboard event C#

Alternatively in a timer, check the content of the clip board and clear it as soon as it is set to a picture.

No, No way to do that. Even if you capture the Print Screen key in your application user might set focus to some other application and then do the Print screen(having your application on side etc.).

Only way would be to create a dummy application in background which captures all keystrokes using Keyboard Hooks and filters Print Screen, but that will happen for all applications not just yours. And moreover as George said user can use cellphone camera too!

I think Microsoft Rights Management System can help. Give it a try. Following is the link:

Microsoft Rights Management System

The only way I can think of is to use the native Windows API (SetWindowsHookEx) to catch all keystrokes and filter out the PrintScreen key. However this would involve creating a native (i.e. unmanaged) DLL to actually do the keystroke processing.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!