TreasonX Posted April 27, 2003 Posted April 27, 2003 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 Quote
aewarnick Posted April 27, 2003 Posted April 27, 2003 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. Quote C#
TreasonX Posted April 27, 2003 Author Posted April 27, 2003 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 :) Quote
aewarnick Posted April 27, 2003 Posted April 27, 2003 If you find anything please post back to let me know. Quote C#
aewarnick Posted June 9, 2003 Posted June 9, 2003 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. Quote C#
*Gurus* divil Posted June 9, 2003 *Gurus* Posted June 9, 2003 If there was one, someone would probably have answered you the first time. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Merrion Posted June 9, 2003 *Experts* Posted June 9, 2003 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... Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Merrion Posted June 9, 2003 *Experts* Posted June 9, 2003 I've put a VB5 version in the sister site VisualBasicForum that should show you what I mean. Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
aewarnick Posted June 9, 2003 Posted June 9, 2003 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. Quote C#
aewarnick Posted June 10, 2003 Posted June 10, 2003 Will that code work even when my app does not have focus? That is what I need. Quote C#
*Experts* Merrion Posted June 10, 2003 *Experts* Posted June 10, 2003 Yup - the clipboard chain is system-wide. Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
aewarnick Posted June 10, 2003 Posted June 10, 2003 Even when my program does not have focus, it will be notified of a change and can act on it right away? Quote C#
Leaders dynamic_sysop Posted June 10, 2003 Leaders Posted June 10, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.