剪切时剪贴板侦听器注册两次

时间:2018-09-05 22:55:00

标签: c# forms listener clipboard cut

只有当我切东西时,它才会记录2次。如何避免这种情况?有没有办法告诉我是复制还是剪切内容?

这是我的代码:

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AddClipboardFormatListener(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
private const int WM_CLIPBOARDUPDATE = 0x031D;

protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_CLIPBOARDUPDATE)
            {
                MessageBox.Show(Convert.ToString("update in clipboard"));
            }
        }

0 个答案:

没有答案