how to disable “PRINT SCREEN” button while running

2019-01-26 09:44发布

How can I disable Print Screen functionality while my WPF application is running?

The use-case is that my client wants to avoid unnecessary replication of valuable patient-centric data from the outside world and they provide the physical security to keep people from taking data through non-digital means.

8条回答
可以哭但决不认输i
2楼-- · 2019-01-26 10:31

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.

查看更多
来,给爷笑一个
3楼-- · 2019-01-26 10:35

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.

查看更多
登录 后发表回答