How to read text from the interface of another application?

A

Andy

Hi,

I want to write a C# windows application that reads some text from the
interface of another (separate) application, and am looking for a few ideas
as to where to start.

Specifically, I would appreciate some help with the following questions:
1) What is the best way to determine how the information I want is held in
the other application?
2) What will probably be the best way to access the information I want.

For question 1, I suspect that the information I want it is in the
equivalent of a label control, but am not sure. It could be a graphic object
of some sort...

For question 2, I am guessing that I will need to use some Win 32 APIs to
get a handle to the window I want, and then perhaps start capturing messages
on it? (That of course assumes that the text I want to capture is neatly
displayed in an object that can be accessed via its handle, however that
might not be the case!)

Thanks in advance.
 
O

Oliver Sturm

Andy said:
I want to write a C# windows application that reads some text from the
interface of another (separate) application, and am looking for a few
ideas as to where to start.

Specifically, I would appreciate some help with the following questions:
1) What is the best way to determine how the information I want is held in
the other application?
2) What will probably be the best way to access the information I want.

For question 1, I suspect that the information I want it is in the
equivalent of a label control, but am not sure. It could be a graphic
object of some sort...

Well, you can do the simple manual checks. Like, can you select the text
with the mouse? If you change the default font in your Windows settings,
does the font change in the control? Get Winspector
(http://www.windows-spy.com/) and see if you can detect anything
interesting about the control.
For question 2, I am guessing that I will need to use some Win 32 APIs to
get a handle to the window I want, and then perhaps start capturing
messages on it? (That of course assumes that the text I want to capture is
neatly displayed in an object that can be accessed via its handle, however
that might not be the case!)

Right. Or you could use GetWindowInfo to query information about the
control. Or you could send a WM_GETTEXT message to the control
(http://shrinkster.com/87j) to read the window text directly. But this
will all only work if the control really has a handle and stores its text
in the "Windows standard" way.

Otherwise, if the text is really graphics, you'll have to use some form of
OCR - come to think of it, AutomatedQA's next version of TestComplete is
supposed to be able to do this: http://shrinkster.com/87k I don't think
you'll be able to use that from your app directly because it will be part
of their tool, but maybe it can give you a few ideas.



Oliver Sturm
 
A

Andy

Thanks very much Oliver - a very useful reply that should set me off in the
right direction.

I've used Spy++ before, but wasn't aware of Windows Spy. It looks good.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top