views:

37

answers:

2

I am using C# to develop an application that works with the clipboard, an was wondering if its possible to get the contents of what the user has selected in the current window, no matter what window it is (e.g. could be FireFox, notepad, etc.).

A: 

If something was only selected, it won't appear in the Clipboard. But if user copied some object that he had previously selected, then, yes, it will be in the Clipboard.

26071986
Yes but I don't want it to have to be in the clipboard. I want to know what the clipboard knows when it copies something - what is selected in the active window.
mchamfist
I think, C.McAtackney gave a link to a good example. I suppose, it can be widened so that to work not only with text.If you want to use the Clipboard class, it can give you some hints of what it contains - by Contain... and Get... methods. But if you want to know what is going to be copied, I'm afraid, it's of no use to you.
26071986
A: 

I'm not sure if you're going to be able to get a general solution for this problem. Take a look at this link;

http://www.eggheadcafe.com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx

The author of this post reports that their solution works in Notepad, but not in Wordpad or Word. I don't know much about this area, but I would guess that this means there are various means through which text selection is implemented - even within Windows.

I think this also extends to Control-C, not just text selection. I believe that there are different ways of handling the copy command depending on the context in which it's used.

For example, if you press Control-C on a dialog box in Windows, it will copy the text without you have to select it manually.

Hopefully the link above is of some use to you. This seems like an interesting problem to overcome.

Edit:

Spoke too soon - just found this link;

http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5

Looks like this is exactly what you're after - hope that works.

C.McAtackney