Clipboard Monitor
<p>I have a problem. I am trying to use the ClipboardMonitor for my C# Application. The goal is to monitor every change in the clipboard.
To start monitoring:</p>
<pre><code>AddClipboardFormatListener(this.Handle);
</code></pre>
<p>To stop the listener:</p>
<pre><code>RemoveClipboardFormatListener(this.Handle);
</code></pre>
<p>And the override WndProc() method:</p>
<pre><code>const int WM_DRAWCLIPBOARD = 0x308;
const int WM_CHANGECBCHAIN = 0x030D;

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case WM_DRAWCLIPBOARD:
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Text))
            {
                ClipboardMonitor_OnClipboardChange((string)iData.GetData(DataFormats.Text));
            }
            break;

        default:
            base.WndProc(ref m);
            break;
    }
}
</code></pre>
<p>And of course the DLL import:</p>
<pre><code>[DllImport(&quot;user32.dll&quot;, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AddClipboardFormatListener(IntPtr hwnd);

[DllImport(&quot;user32.dll&quot;, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
</code></pre>
<p>But when putting a breakpoint at the method call <code>ClipboardMonitor_OnClipboardChange</code> and changing the clipboard, I never get the method called.</p>
<p>How can I change my code so that I receive a WM_ message notifying me that the clipboard has changed?</p>