Has Clipboard contents changed?

TreasonX

Member
Joined
Apr 16, 2003
Messages
6
Is there anyway to have the clipboard notify a program if the contents have been changed? Right now, i am considering a timer to check the contents of the clipboard and then compare to the last thing taken from the clipboard. Is this the best way to tell if the contents have been changed? I have looked in MSDN but have come up with nothing.

Thanks

James
 
As far as I know, yes. But if there is an event handler for Object_Changed or something I would like to know about it.
 
Thats what I was actually looking for. But looks like the timer is my best bet.. Seems like a waste and there has to be a better way. Ill keep looking :)
 
Now I need an answer to this post. If anyone knows of an EventHandler that is called when the clipboard contents are changed please let us know.
 
If there was one, someone would probably have answered you the first time.
 
Theres an API way.

Using:
Code:
Declare Function SetClipboardViewer Lib "user32" Alias "SetClipboardViewer" (ByVal hwnd As Long) As Long
Declare Function GetClipboardViewer Lib "user32" Alias "GetClipboardViewer" () As Long
Declare Function ChangeClipboardChain Lib "user32" Alias "ChangeClipboardChain" (ByVal hwnd As Long, ByVal hWndNext As Long) As Long
Public Const WM_DRAWCLIPBOARD = &H308
Public Const WM_CHANGECBCHAIN = &H30D

When your form loads you havd a private variable mhwndNextCBViewer As Int32 which you set on form load thus:

Code:
mhwndNextCBViewer = SetClipboardViewer(Me.hwnd)

Then when you get the message WM_DRAWCLIPBOARD you know that the clipboard has changed. You also have to handle the WM_CHANGECBCHAIN message if it tells you that your mhwndNextCBViewer has been removed from the clipboard chain.

If I get any spare time Ill try and knock together a component to wrap this functionaility...
 
Thank you Merrion. You were very helpful! Although it will take me a while to figure this out. I only know some C# and almost no VB.
 
Even when my program does not have focus, it will be notified of a change and can act on it right away?
 
if you set the form to be your clipboard viewer it doesnt matter about having focus , because if you are listening for changes on the clipboard these messages will pass through your form anyway. so whenever the data changes you should get notified of it.
 
Back
Top