加入剪贴板链最佳实践 [英] Joining the Clipboard Chain Best practices

查看:65
本文介绍了加入剪贴板链最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在自定义格式剪贴板上的帖子上,我正在考虑编写自己的自定义clipboad监视组件的可能性。

Further to my post on custom format clipboard, I am considering the possibility of writing my own custom clipboad monitoring component.

在语句之前:

ClipboardWindow:=SetClipboardViewer(Form1.Handle);

我在示例代码中看到我研究了以下代码段:

I have seen in a sample code I studied the following snippet:

OpenClipboard(Form1.Handle); 
EmptyClipboard; 
CloseClipboard;

而其他人根本没有包含清洁代码。我很困惑。

whereas others don't include a cleaning code at all. I am confused.

我相信 Clipbrd.TClipboard.Clear 的行为与VCL相同。

I believe Clipbrd.TClipboard.Clear just does the same the VCL way.

我的问题是:

在加入剪贴板链是必需项吗?

推荐答案

不,不需要清除剪贴板。确实,你不应该。其他剪贴板监视器将不必要地对更新做出反应,并且用户可能希望粘贴刚破坏的东西。
此外,剪贴板链监视还不仅仅是将自己添加到链中。您必须将事件传递到下一个窗口(SetClipboardViewer的结果句柄),并且必须在应用退出时无故障地将自己从链中移出。另外,您需要避免不必要地阻塞剪贴板。通常,这意味着等待注册剪贴板事件,直到您准备好实际处理事件为止。例如,如果要随后打开一个对话框,询问用户他想将数据存储在何处,是否具有许可证密钥等,则不要在启动时首先考虑它。

No, there is no need to clear the clipboard. Indeed, you shouldn't. Other clipboard monitors will needlessly react to the update, and the user may want to paste that thing that you just destroyed. Additionally, there is a lot more to clipboard chain monitoring than just adding yourself to the chain. You must pass the events along to the next window (result handle from SetClipboardViewer), and you must, without failure, remove yourself from the chain when your app exits. Also, you need to avoid blocking the clipboard unnecessarily. Typically, this means waiting to register for the clipboard events until you're ready to actually process events. For example, don't make it the first thing in your startup, if you're going to subsequently open a dialog asking the user where he wants to store the data, if he has a license key, etc..

我这里有一些提示以及常见的陷阱:
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6

I have tips, as well as common pitfalls here: http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6

这篇关于加入剪贴板链最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆