剪贴板更改通知?
我知道如何将内容放入剪贴板以及如何从剪贴板检索内容。
但是,在这两个操作之间,另一个操作可能会更改剪贴板的内容。
有没有办法在任何应用程序修改剪贴板时收到通知?
I know how put content to and retrieve content from the clipboard.
However, between these two operations, it is possible for another operation to change the content of the clipboard.
Is there a way to be notified when any application modifies the clipboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要添加的唯一参考是 wpf 应用程序中的 Windows 窗体。我为我在互联网上找到的功能创建了一个包装器。
大多数示例所做的事情超出了我的需要,因此我决定创建自己的类。我喜欢隔离问题,因此此类仅在剪贴板更改时进行监听,并告诉您剪贴板上的数据类型。例如它是文本吗?一个图像?或者什么?
无论如何,这是我的包装:
我知道它可能太多了,但包装后它应该看起来像:
然后将该类用作:
The only reference you need to add is to windows forms in your wpf application. I created a wrapper to the functionality I found on the internet.
Most of the examples do more stuff than what I needed so I decided to create my own class. I like to isolate the problems so this class just listens when the clipboard changes and tells you the type of data that is on the clipboard. For example is it text? an image? or what?
Anyways here is my wrapper:
I know it might be to much but but after wrapping it it should look like:
And then you use the class as:
我能找到的只是一个用 C#/VB.NET 编写的 剪贴板监视器。我看到了 WPF 和 WinForms,所以我假设这是一个可行的选择。
涉及 pinvoking user32 dll 中的一些方法。
编辑
在编辑时,上面的原始链接已损坏。这是 archive.org 快照
All I could find was a Clipboard Monitor written in C#/VB.NET. I see WPF and WinForms, so I assume this is a viable options.
Involves pinvoking some methods from the user32 dll.
EDIT
At the time of edit, the original link above is broken. Here's an archive.org snapshot
当应用程序调用 OpenClipboard() 时,其他应用程序不能使用剪贴板。一旦锁定剪贴板的应用程序调用 CloseClipboard(),任何应用程序都可以使用并锁定剪贴板。
是的。请参阅 API SetClipboardViewer() 以及消息 WM_DRAWCLIPBOARD 和 WM_CHANGECBCHAIN。
更多信息请参见:http://msdn.microsoft.com/en-us/library/ms649016(v=vs.85).aspx#_win32_Adding_a_Window_to_the_Clipboard_Viewer_Chain
When an application calls OpenClipboard(), no other application can use the clipboard. Once the application that has locked the clipboard calls CloseClipboard(), then any application can then use and lock the clipboard.
Yes. See the API SetClipboardViewer() and the messages WM_DRAWCLIPBOARD and WM_CHANGECBCHAIN.
More info here: http://msdn.microsoft.com/en-us/library/ms649016(v=vs.85).aspx#_win32_Adding_a_Window_to_the_Clipboard_Viewer_Chain
这是我几年前写的一篇文章,详细介绍了剪贴板甚至通过 Windows API 进行监控:
http://www.clipboardextender.com/developing-clipboard-aware -programs-for-windows/6
请特别注意“常见错误”部分。几乎没有人第一次就能正确地做到这一点。
Here is a write-up that I did a few years ago, detailing clipboard even monitoring via the Windows API:
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6
Please pay particular attention to the "common mistakes" section. Hardly anyone does this correctly the first time.