Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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 :)
  • 1 month later...
  • *Experts*
Posted

There's an API way.

 

Using:

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:

 

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 I'll try and knock together a component to wrap this functionaility...

Printer Monitor for .NET? - see Merrion Computing Ltd for details
  • Leaders
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...