Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

911 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

23 Experts available now in Live!

Get 1:1 Help Now