Sign in to follow this  
Kruzty

Getting text from another windows app

Recommended Posts

I haven't done much windows-specific programming so I'm sorry if this is obvious to you veterens . Anyway, I want to be able to pull in text (in real time) from an edit box in another windows app, and then send that app keystrokes and or mouse moves/clicks. I really don't have any idea where to start figuring out how to do this. Can anyone point me to tutorials or other sources of info about doing this? Thanks a lot!

Share this post


Link to post
Share on other sites
If you know the window you're looking for is on top, then use GetForegroundWindow() or GetTopWindow() to get the main window handle. Otherwise, you'll have to use GetTopWindow() followed by a series of calls to GetNextWindow() to enumerate through all windows to find what you're looking for. Once you've got the window handle, use GetDlgItem() to get a handle to the control you're looking for. Note that this requires knowing the control's resource ID. If you do not know the RID, you can do a for loop from 0 to 65535 and test the result with something such as SetFocus() to figure out the RIDs of each control. Once you figure it out, you can use the same number each time, since the RIDs will almost always be the same. Once you have the handle to the control you want, you can call SetWindowText() to set the text, or if you want to simulate the user typing or using the mouse, you can use SendInput().

Share this post


Link to post
Share on other sites
I would use FindWindow or rather FindWindowEx rather than Get Foreground/Top/Next Window.
Also, use spy++ to find out which control it is that you want i.e. it may be the third control in the window.

Share this post


Link to post
Share on other sites
Thanks for the help guys, I've been able to make some progress, but I'm still not there.

What I'm trying to do is make a "chat bot", so I need to be able to read other peoples posts as they are delivered to the chat app. I have been able to find the right window and the control that has the chat history in it (and verified with spy++), but WM_GETTEXT doesn't give me the content of the "chat history" screen.

Using spy++ I was able to watch the messages arriving to the control and saw that every time it got a new line of text to display it got the same message (WM_USER + 30). One of the parameters in NULL and the other has what I assume to be a pointer to the text to display (this pointer is always the same).

I tried using ReadProcessMemory() to read the pointer. To get process handle I used GetWindowThreadProcessId() with the window handle. (Is this the right thing to do? I get back a DWORD, not a HANDLE). I then hard coded the pointer to read from and tried to read it, but I get back 0 bytes.

Anyone have any suggestions? Should I be able to read another process's memory like that? Assuming I can read the memory, will I be able to intercept the messages in my program the way spy++ does?

Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this