Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 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