Detecting selected text
-
Is there any way to detect selected text in another window. As a example there is a form with a text box and it's minimized in the system tray. When a user select a text in a window or another program(like word, excel etc.) that minimized form should appear and selected text should place in the text box. If this is possible, please someone give me an idea to do this.
-
Is there any way to detect selected text in another window. As a example there is a form with a text box and it's minimized in the system tray. When a user select a text in a window or another program(like word, excel etc.) that minimized form should appear and selected text should place in the text box. If this is possible, please someone give me an idea to do this.
Asked and answer many times. There is no reliable method to detect text being selected in every application. You'd have to write methods for generic methods you could TRY on selected apps, but there is nothing that will work in all cases. Also, there are apps where no matter what you do you couldn't detect this at all.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Is there any way to detect selected text in another window. As a example there is a form with a text box and it's minimized in the system tray. When a user select a text in a window or another program(like word, excel etc.) that minimized form should appear and selected text should place in the text box. If this is possible, please someone give me an idea to do this.
Yes, this is possible in most circumstances. The first problem is in identifying which window you care about. Multiple applications can have text selected at the same time. You can make clever use of FindWindow() and FindWindowEx() to get a handle to the window in question. The second problem is in identifying the GUI element on that window that might have text that you are interested in. This is actually a much more complicated problem since the GUI element could be any sort of object, nested anywhere on the window. You could use GetWindow() to help with this. The third problem is telling what text is selected within that GUI element. The way you do this depends on the GUI element in question. In a few cases, it may not even be possible. I'm not really sure where I would begin to try to crack that nut. There are a ton of useful API calls that you can use at http://msdn.microsoft.com/en-us/library/ff468919%28v=VS.85%29.aspx[^] You might almost be better off thinking about this problem differently. You could, for example, set up some global system hooks to capture the relevant mouse and keyboard events that occur when text is selected. Then, you would have immediate and direct insight into the objects with which you were dealing. Read this article for an idea of where to start with that approach: Global System Hooks in .NET[^] Good luck.