views:

225

answers:

2

Hi .. i have a problem using the "Catch Clipboard Events code" found on this link :

http://stackoverflow.com/questions/621577/clipboard-event-c/2487582#2487582

the code works great only if the form stays in the foreground, not minimized to tray BUT: if you add a notifyicon and minimize the form to tray and turn the showintaskbar to false (so that you only have an icon in the tray), the program wont catch any clipboard changes anymore ... even if you maximize the form back, it wont work again ...you have to restart the program ..

any idea on how to solve this issue !? how can i catch clipboard changes, even if the form is minimized into the tray !?

any help is really appreciated ...

Thanks

+1  A: 

It should work if minimized - really minimized though, or hidden. If your implementation of "minimized" invovles destroying the window, then that handle is invalid. And the clipboard chain is now broken for whatever was listening to clipboard events downstream...

Throw some debug code in there to display this.Handle as a string (ex: "123456"). Put the call to SetClipboardViewer in a click event on the form. Click it, see the number. Minimize, restore. Click again. Do you have the same number? you should. If not, then there lies the problem. The clipboard events MUST go to a window that stays around. It can be a hidden window in the background.

-- Chris

Chris Thornton
So, did you try my idea, and if so, did the handle remain constant, or did it change?
Chris Thornton
Knock Knock....
Chris Thornton
hi Chris ...sorry have been away the whole last week ..i will give it a try, but i did try smthg like this before ..the idea with the invisible form is good, i will try it and tell you ..thanks again
lebhero
NP - I'm glad you're still alive. Let me know.
Chris Thornton
A: 

So anyway, you could have another form that's hidden, and use that to catch the windows messages. Never close/re-create that window. It opens at startup, stays open, but invisible. This will work.

Chris

Chris Thornton
hi Chris .. i just finished trying your suggestion, and it works ... iam not sure, but it seems to be that the this.ShowInTaskbar=false; will kill the form, or at least in my condition the handle will become invalid .. so just minimize to tray, and it works great :) thanks again for the help
lebhero
Great! Don't forget to upvote and accept. If the trick about displaying the handle ID helped, upvote that one and leave this one to rot. Thanks.
Chris Thornton