3

is it possible for it to detect and differentiate cut,copy, or paste of files? I only can detect a change in the clipboard to far.

public partial class Form1 : Form
{
    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SetClipboardViewer(IntPtr hWnd);

    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

    private IntPtr _ClipboardViewerNext;

    private const int WM_DRAWCLIPBOARD = 0x0308;
    //  private const int WM_CUT = 0x0301;

    public Form1()
    {
        InitializeComponent();
    }

    private void StartClipboardViewer()
    {
        _ClipboardViewerNext = SetClipboardViewer(this.Handle);
    }

    private void StopClipboardViewer()
    {
        ChangeClipboardChain(this.Handle, _ClipboardViewerNext);
    }

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        if (m.Msg == WM_DRAWCLIPBOARD)
        {
            MessageBox.Show("Copied");
            SendMessage(_ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
        }
        else
        {
            base.WndProc(ref m);
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        StartClipboardViewer();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        StopClipboardViewer();
    }

}
Steve
  • 213,761
  • 22
  • 232
  • 286
RStyle
  • 875
  • 2
  • 10
  • 29
  • 1
    No, that's a program implementation detail that you can't see with a clipboard viewer. You only see changes to the clipboard. – Hans Passant Mar 28 '12 at 13:17

2 Answers2

1

No, but you could write a wrapper for the Clipboard (as it's a sealed class you can't derive from it) to keep track of the get/set operations.

Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55
0

The clipboard does not differentiate between cut and copy. It's a semantic difference in the way that the source application treats the data (or files).

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62