Solved

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

Posted on 2008-10-25
2
1,002 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

778 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