如何禁用“打印屏幕”在 WPF 中运行我的应用程序时按钮?

发布于 2024-09-26 07:37:04 字数 101 浏览 3 评论 0原文

如何在 WPF 应用程序运行时禁用打印屏幕功能?

用例是,我的客户希望避免从外界不必要地复制以患者为中心的宝贵数据,并且它们提供物理安全性以防止人们通过非数字方式获取数据。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

爱给你人给你 2024-10-03 07:37:04

好吧,这是可能的,如果您的应用程序部署在用户无法使用相机的环境中,并且确实很有用。

首先,我使用了 RegisterHotKey 和 UnregisterHotKey API 调用,记录在此处 http://pinvoke.net/ default.aspx/user32.RegisterHotKey 如这篇相当旧的文章中所述 http://msdn.microsoft.com/en-us/magazine/cc163713.aspx

我在 Window_Load 事件中注册了 IDHOT_SNAPDESKTOP 热键,并在 Window_Closed 中取消注册。尝试在构造函数中执行此操作给我带来了使用 WindowInteropHelper(this) 方法获得一致句柄的问题。

如果您想做的不仅仅是忽略按键,您可以设置一个 Windows 消息处理程序,使用一种 WndProc,

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

如上所述制作句柄,然后自己实现 WndProc。

到目前为止,我不知道如何“不”处理热键并使窗口执行其正常行为,当然,除非取消注册热键。

它不是很优雅或“WPF”,但它对我有用。


作为@ghord评论

使用EnsureHandle() 看起来对于在构造函数中获取处理程序很有用。

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.

夜空下最亮的亮点 2024-10-03 07:37:04

禁用打印是不可能的,即使可以,手机摄像头也很容易绕过它。许多分辨率都在百万像素范围内,这使得人们很容易获得他们想要的信息。

如果您想禁用键盘上的Print Screen键,Jodrell 的答案给出了一种方法 (了解它不会阻止人们打印,并且坚定的用户会找到解决方法)。

确实,这一切都取决于信任。如果雇主不能相信其员工不会删除大多数司法管辖区(美国的 HIPAA)已受法律保护的数据,那么就会出现更大的问题。

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.

北方的巷 2024-10-03 07:37:04

简单的:

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

Easy:

Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
活泼老夫 2024-10-03 07:37:04

简单来说,你不能。 “打印屏幕”只是将屏幕上的像素复制到剪贴板,而不是您的应用程序的一部分。

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

就是爱搞怪 2024-10-03 07:37:04

基本上,您可以挂钩 ClipBoard 事件,然后将复制的图像设置为空(如果有人这样做)。因此他们可以复制图像,但图像会被重置:

看看这个:

剪贴板事件 C#

或者在计时器中,检查剪贴板的内容并在设置为图片后立即将其清除。

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.

栩栩如生 2024-10-03 07:37:04

不,没办法这么做。即使您在应用程序中捕获了“打印屏幕”键,用户也可能会将焦点设置到其他应用程序,然后执行“打印屏幕”(将您的应用程序放在一边等)。

唯一的方法是在后台创建一个虚拟应用程序,使用键盘挂钩和过滤器打印屏幕捕获所有击键,但这对于所有应用程序都会发生,而不仅仅是您的应用程序。而且正如乔治所说,用户也可以使用手机摄像头!

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!

鱼忆七猫命九 2024-10-03 07:37:04

我认为 Microsoft 权限管理系统可以提供帮助。尝试一下。以下是链接:

Microsoft 权限管理系统

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

Microsoft Rights Management System

淡笑忘祈一世凡恋 2024-10-03 07:37:04

我能想到的唯一方法是使用本机 Windows API (SetWindowsHookEx) 捕获所有击键并过滤掉 PrintScreen 键。然而,这将涉及创建一个本机(即非托管)DLL 来实际执行击键处理。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文