views:

574

answers:

3

Specifically, a program is running and I want to extract the text from a text box inside the program.

Generally, what methods/topics should I be using to "get inside" another .exe running on my system and extract data from a text box inside it using C++?

I just want a pointer towards the way in which I might achieve this. Thanks.

+4  A: 

You can simply use EnumChildWindows and SendMessage with WM_GETTEXT to the specific window you want to get the text from.

Blindy
+4  A: 

Another common technique for 'getting inside' a GUI application (windows specific) is DLL Injection + Windows Subclassing. This is probably considered somewhat advanced windows programming an excellent Book on the subject is 'Windows Via C/C++'. A brief idea of what this about is essentially:

  1. Inject your custom DLL into the address space of the target program.
  2. Find the HWND for the target text box.
  3. Subclass the functions which are relevant to the changing/editing of this text box.
  4. Now any time someone edits/the text is changed, your function will first be called, allowing you to see/manipulate the text. You can even choose to not forward it onto the normal handler.

Also note that nothing I have mentioned above is in any way 'hacking windows' this is a well defined behavior which was implemented purposely by Microsoft. Its quite well documented over on MSDN actually.

If you want to do this have a look at 'Windows Subclassing' and 'Setting Hooks'.

DeusAduro
A: 

See How I Built a Working Online Poker Bot: Extracting Text from 3rd-Party Applications for an explanation of the inject-and-subclass techniques mentioned by @DeusAduro as well as a couple other techniques for the same, such as hooking the GDI text-output APIs. And of course if it's a standard textbox you can always send a WM_GETTEXT this works even across process boundaries (was designed to work across process boundaries in fact).

James D