我想有这个功能在我的C#程序:当用户做Ctrl + C或复制任何地方(即当剪贴板内容发生变化),我的程序会得到通知,并检查内容是否符合一定的标准,如果是的话,成为活动程序,并处理内容等。
I want to have this feature in my C# program: When the user do Ctrl+C or Copy anywhere (i.e. when the clipboard content changes), my program will get notified, and check whether the content met certain criteria, if so, become the active program, and process the content, etc.
我可以从 System.Windows.Forms.Clipboard
得到的内容了,但是,我不知道如何监视剪贴板中的内容发生变化。
I can get the contents out from System.Windows.Forms.Clipboard
, however, I don't know how to monitor the content changes from the Clipboard.
干杯,
编辑:如果使用Vista或更高版本,使用 AddClipboardFormatListener
在约翰Knoeller的回答,XP,必须使用较旧的,比较脆弱 SetClipboardViewer
API,作为公认的答案。
If using Vista or later, use AddClipboardFormatListener
as in John Knoeller's answer, for XP, have to use the older, more fragile SetClipboardViewer
API, as in the accepted answer.
推荐答案
您可以使用的 SetClipboardViewer 通过WIN32 API提供的(通过的P / Invoke)。
You could use SetClipboardViewer provided by win32 API (through p/invoke).
下面是一个页面,其中包含code来设立一个在C#:http://www.$c$cguru.com/csharp/.net/net_general/tipstricks/article.php/c7315/
Here is a page which contains code to set one up in C#: http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c7315/
相关推荐
最新文章