剪贴板事件C# [英] Clipboard event C#
本文介绍了剪贴板事件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
我想你必须使用一些p / invoke:
[DllImport(User32.dll,CharSet = CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
请参阅本文介绍如何在c#中设置剪贴板监视器
基本上,您使用
_ClipboardViewerNext = SetClipboardViewer(this.Handle)注册您的应用程序作为剪贴板查看器;
然后您将收到 WM_DRAWCLIPBOARD
消息,您可以通过覆盖 WndProc
来处理:
protected override void WndProc (ref Message m)
{
switch((Win32.Msgs)m.Msg)
{
case Win32.Msgs.WM_DRAWCLIPBOARD:
//处理剪贴板已更改
break;
// ...
}
}
(有更多的要做;沿着剪贴板链传递东西,取消注册你的视图,但是你可以从文章)
Is there a clipboard changed or updated event that i can access through C#?
解决方案
I think you'll have to use some p/invoke:
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
See this article on how to set up a clipboard monitor in c#
Basically you register your app as a clipboard viewer using
_ClipboardViewerNext = SetClipboardViewer(this.Handle);
and then you will recieve the WM_DRAWCLIPBOARD
message, which you can handle by overriding WndProc
:
protected override void WndProc(ref Message m)
{
switch ((Win32.Msgs)m.Msg)
{
case Win32.Msgs.WM_DRAWCLIPBOARD:
// Handle clipboard changed
break;
// ...
}
}
(There's more to be done; passing things along the clipboard chain and unregistering your view, but you can get that from the article)
这篇关于剪贴板事件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文