System Programing

 

Saturday, May 30, 2009

Detect Windows Clipboard Change

// Detect Windows Clipboard Change

// ...

[DllImport("user32.dll")]
public static extern int SetClipboardViewer(int hwnd);

public Form1() {
InitializeComponent();
SetClipboardViewer(this.Handle.ToInt32());
}

protected override void WndProc(ref Message m) {
base.WndProc(ref m);

// chkClipboard isn't checked initially
// so this prevents MessageBox on Form load:

if (m.Msg == 776 && chkClipboard.Checked)
{
// Clipboard change!
}
}

No comments:

Post a Comment

All Menu