0

Possible Duplicate:
How can an app hook into text selection system-wide?

I'm going to be creating a look up program that will probably be operating similar to a Windows Shell kind of application. In Outlook, I'm going to select an ID number (text) and my application needs to accept that as an argument to do things with that.

How can I access the selected text on a global (Windows) scale?

My workaround is probably to execute a Copy action then read the Clipboard's contents. But I'd like to keep that free if possible.

Community
  • 1
  • 1
ikathegreat
  • 2,311
  • 9
  • 49
  • 80
  • possible duplicate of [How can an app hook into text selection system-wide?](http://stackoverflow.com/questions/3526483/how-can-an-app-hook-into-text-selection-system-wide) See also: http://stackoverflow.com/questions/9606041 and http://stackoverflow.com/questions/7509483 – mellamokb Aug 20 '12 at 20:01
  • "execute a Copy action" without the user initiating it is a very, very bad idea.. – banging Aug 20 '12 at 20:02
  • how so? it's text, not security-related keys or the like. There are plenty of applications that access data in other apps. i guess can you expand on that. – ikathegreat Aug 20 '12 at 20:08
  • 1
    @ikathegreat- The reason that it's not a good idea to execute a 'Copy' without the user initiating it is because the user isn't expecting it and doesn't know that it's happening. If the user had something stored on the clipboard, then your app-initiated copy would silently throw out the user's data (which is never a good thing). Users expect to be in complete control of the clipboard at all times. – bta Aug 20 '12 at 20:20
  • @bta fair enough. this i'm finding out conflicts with Outlook's create a new contact action...does anyone know if the selected text is accessible through an Add On (VBA)? – ikathegreat Aug 20 '12 at 21:30

2 Answers2

1

See the solution in this thread: Copy Selected Text from any window

Basically, you will need to use PInovoke to get the selected text from the active window. Additionally, you could set up a windows key binding to run your application and trigger the action. This approach has the added benefit of working for all applications, not just Outlook.

Malgaur
  • 1,842
  • 15
  • 17
0
  1. you can use spy++ to set a target on the control you want to get ID
    1. Use an API windows
      [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); it allows you to get text from the control (textbox or other caption)
Hassan Boutougha
  • 3,871
  • 1
  • 17
  • 17
  • would happen to have an example on how to do this? My target application is Outlook 2010, I need to acquire the selected text there. – ikathegreat Aug 20 '12 at 21:29