Solved

How to get the text out of another program's text box

Posted on 2008-10-25
2
999 Views
Last Modified: 2008-10-29
I need my program to be able to read another program's text box, being shown in that program's window.  I will already have the window's handle for other reasons.

Question 1 - How can I read that information?  I understand the general idea that the other program is going to have certain widgets, some being images, others being buttons, and one being a text box.  How can I get whatever parameter is needed to programatically identify the text box, and how do I read the information in the text box?

Question 2 - This text box will be constantly changing, and I will need to read it every time it changes.  Is there a way I can register an event for when that text box changes, for it to call my program?  (The program I'm reading from doesn't have any type of API to interface with.)  Or, is the only way for me to accomplish this to be reading the text box at a certain interval like every half second or second and see if it changed?  I would prefer for a change in the text box to trigger my program for efficiency.

As you might tell, I don't have any experience with graphical applications or the win32 api, but I do have many years experience in unix based cgi and database programming, so if you can point me in the right direction I can go from there.  Once I know the names of functions I'll be using, I'm fully capable of researching them a bit further.
0
Comment
Question by:darlingm2
2 Comments
 
LVL 11

Accepted Solution

by:
alexcohn earned 250 total points
ID: 22806928
You can subclass an text box as described in http://msdn.microsoft.com/en-us/library/bb773183(VS.85).aspx and handle WM_COMMAND messages, looking for EN_CHANGE notifications (see http://msdn.microsoft.com/en-us/library/bb761676(VS.85).aspx). If you have a handle to parent window (e.g. dialog), you can enumerate all its children (use GetWindow() API ) and find the child (or children) whose window class is "EDIT".
0
 
LVL 4

Assisted Solution

by:chip3d
chip3d earned 250 total points
ID: 22806937
Hi darlinqm2,

you could use the windows API together with WinEvents. If you have the Windowhandle of the main window of the app with the textfield you can use the EnumChildWindows-function to enumerate all child windows and try to find the textbox by the classname (GetClassName) or you could try to use the FindWindowEx function.

For reading the content of the textbox you can use the GetWindowText-function or create a MSAA-Object and use the getValue-method. For simple windows textboxes you also could use the windowsmessages: SendMessage with EM_GETLINE, EM_GETSEL if you would like to have more information about the textbox.

To get a notification for changes in the textbox install a winevent hook for the event EVENT_OBJECT_VALUECHANGE:

register events:
SetWinEventHook(EVENT_OBJECT_LOCATIONCHANG,EVENT_OBJECT_LOCATIONCHANG,0,winEventProc,GetWindowThreadProcessId(textboxwindow,0),0,WINEVENT_OUTOFCONTEXT);

Don't forget to check within the callback that the event really belongs to the textboxwindow. Now you can update your programm...

Some intersting tools that could help you with finding classname of the textbox and other informatione are:
http://www.microsoft.com/downloads/details.aspx?familyid=3755582A-A707-460A-BF21-1373316E13F0&displaylang=en

regrads,
chip3d
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now