Detect Clipboard Change

vendiddy

Well-known member
Joined
May 14, 2006
Messages
64
Programming Experience
1-3
I want to make kind of a clipboard utility, where if the user copies some text anywhere in Windows, the application will know the clipboard has changed.

I don't really want to set a timer to check the content of the clipboard every few seconds. Does anyone know a better way to do this?

Thank you.

This is in Visual Studio 2005 by the way.
 
I don't believe there is any functionality in the framework to detect clipboard changes. But i may be mistaken, however in the meantime see the attached project. I think you'll find it very usful, even though it's written in .Net 2003
 

Attachments

  • ClipNotifierVB.zip
    24.4 KB · Views: 200
Win32 API method SetClipboardViewer lets you subscribe to WM_DRAWCLIPBOARD messages that will tell if clipboard contents have changed. MSDN reference: http://msdn.microsoft.com/library/d...nce/clipboardfunctions/setclipboardviewer.asp

Here is an article "Create a Windows Clipboard Monitor in C# using SetClipboardViewer" that explains and there is also VB.Net example, http://www.radsoftware.com.au/articles/clipboardmonitor.aspx

(edit: it's the same functionality as in vis781s attachment, strangely I didn't see that attachment when I posted, probably just a refresh issue, there are lots of asynchronous features with this vBulletin board..)
 
Thank you for the help. I tried the program in the attachment. Everything works, but when I close the application by clicking the X button, an error is thrown. (See attachment)

Does it need to somehow 'unsubscribe' to the WM_DRAWCLIPBOARD messages before closing?
 

Attachments

  • ClipNotifierVB_error.jpg
    ClipNotifierVB_error.jpg
    71.2 KB · Views: 106
I was hoping it would upgrade ok, guess i should have tested it first. The second link in JohnH's post has a class that you will be able to use. Meanwhile i'll have a look into why that exception is being thrown
 
Back
Top