对于我正在编写的小型实用程序(.NET、C#),我想监视剪贴板复制操作和剪贴板粘贴操作。
我的想法是在粘贴到任意应用程序时提供我自己的数据。
使用剪贴板查看器可以轻松监控复制操作。
对我来说,似乎更先进的是编写一个“剪贴板粘贴提供程序”:
- 回答应用程序的“可用格式”查询。
- 向应用程序粘贴操作提供数据。
我发现此帖子和此帖子,但它们似乎都没有真正帮助我。
我想我必须以某种方式模仿/劫持当前剪贴板。
问题:
是否可以在粘贴操作方面“包装”剪贴板并提供我自己的“剪贴板代理”?
For a small utility I am writing (.NET, C#), I want to monitor clipboard copy operations and clipboard paste operations.
My idea is to provide my own data when pasting into an arbitrary application.
The monitoring of a copy operation can be easily done by using a clipboard viewer.
Something that seems much more advanced to me is to write a "clipboard paste provider":
- Answer to "what formats are available" queries of applications.
- Supply data to application paste operations.
I found this posting and this posting, but none of them seems to really help me.
What I guess is that I somehow have to mimic/hijack the current clipboard.
Question:
Is it possible to "wrap" the clipboard in terms of paste operations and provide my own kind of "clipboard proxy"?
发布评论
评论(2)
查看 WinAPI 中的“延迟渲染”。使用这种技术,您可以使用空句柄加载剪贴板,并且在粘贴时,Windows 会通过 WM_RENDERFORMAT 消息通知您。这就是 Excel 等应用程序可以“复制”25 种不同格式的方法。它并没有真正复制它们。它实际上会生成一些常见的内容,例如文本,但“通告”其他内容,例如位图、Html、WKS 等,选择等待查看目标应用程序想要粘贴的内容。
考虑一下:您可以在 Excel 中选择 5000 个单元格并进行复制,并且剪贴板更新得非常快。现在粘贴到 Windows Paint 中,当 Excel 尝试渲染一个巨大的位图时,您的系统突然开始爬行。在使用所有可用内存并吃掉页面文件后,旧版本通常会崩溃。不过这已经是 Windows 3.1 时代的事了。现代版本会给出有关“位图太大”或“内存不足”的消息。
警告:延迟渲染将由监视剪贴板并自动将数据粘贴到自身的应用程序过早触发,例如远程桌面、VMWare、Office Clipboard 和我自己的 ClipMate。可以使用 CF_Clipboard_Viewer_Ignore 标志告诉某些剪贴板监视程序忽略剪贴板更新,我已在此处记录了该标志:
链接文本
Look into "delayed rendering" in the WinAPI. With this technique, you load the clipboard with null handles, and upon pasting, windows notifies you with a WM_RENDERFORMAT message. This is how apps like Excel can get away with "copying" 25 different formats. It doesn't really copy them all. It'll actually produce some common ones like TEXT, but "advertises" the others like Bitmap, Html, WKS, etc., opting to wait to see what the target application wants to paste.
Consider this: you can select 5000 cells in Excel and copy, and the clipboard is updated pretty quickly. Now paste into Windows Paint, and suddenly your system crawls as Excel tries to render a huge bitmap. Older versions would usually crash, after using all available memory and eating the pagefile. This was back in the Windows 3.1 days though. Modern versions give a message about "bitmap too large" or "not enough memory".
Warning: Delayed Rendering will be prematurely triggered by apps that monitor the clipboard and auto-paste data into themselves, such as Remote Desktop, VMWare, Office Clipboard, and my own ClipMate. Some clipboard monitoring programs can be told to ignore the clipboard update by using the CF_Clipboard_Viewer_Ignore flag, which I've documented here:
link text
您需要使用 Windows 挂钩来挂钩剪贴板挂钩。 Windows 挂钩是一种拦截发生的全局事件并提供您自己的挂钩过程来替换或拦截消息的方法。看看 CodeProject ,它解释了如何挂钩。这是一个监听复制/粘贴功能的剪贴板助手。这是一个 剪贴板间谍 就可以做到这一点。这是另一篇实现剪贴板挂钩的文章。
You need to hook in the clipboard hook by using a windows hook. A windows hook is a way of intercepting global events happening and providing your own hook procedure to replace or intercept the message. Have a look here on CodeProject that explains how to hook. Here's a clipboard helper that listens for the copy/paste functionality. Here's a Clipboard spy that just does that. Here's another article that implements a Clipboard hook.