Solved

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

Posted on 2008-10-25
2
1,007 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

623 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