(C#)监听剪贴板
作者:互联网
public partial class Form1 : Form { public Form1() { InitializeComponent(); AddClipboardFormatListener(this.Handle); } protected override void WndProc(ref Message m) { if (m.Msg == WM_CLIPBOARDUPDATE) { Console.WriteLine("剪贴板内容改变"); } base.WndProc(ref m); } //--------------------- public const int WM_CLIPBOARDUPDATE = 0x031D; [DllImport("user32.dll", SetLastError = true)] public static extern bool AddClipboardFormatListener(IntPtr hWnd); [DllImport("user32.dll", SetLastError = true)] public static extern bool RemoveClipboardFormatListener(IntPtr hWnd); }
Form Close事件中再调用RemoveClipboardFormatListener:
RemoveClipboardFormatListener(this.Handle);
标签:剪贴板,RemoveClipboardFormatListener,C#,hWnd,WM,WndProc,public,static,监听 来源: https://www.cnblogs.com/PER10/p/16586924.html