Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen Scraping a Window

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I have been asked by a customer to provide a piece of software that will screenscrape the active window looking for a 'part-number', then display additional information in a pop-up form.

Originally, this was just just for a AS/400-Telnet session (which I found a tutorial for), but the company also use a Windows application to access the AS/400 programs in a similar way.

So I have the following questions:
1. Is it possible to screenscrape the 'active' window?
2. Is it possible to identify the type of window (i.e. to differentiaie between an AS/400 emulator and MS Word)?
3. Would it be possible to have the VB program running in the background and triggered to activate when the 'active' window changes?

Any information would be appreciated. Thanks.
 
It sounds like this task may be too big for vb, however you can identify which window is active and monitor for when it changes by using a system hook. Here is a very good example.



as for 'screen scraping' I assume you mean trying to pick up a piece of text on the screen? It doesn't sound like something that will be easy to do.

Matt

If you can keep your head while those around you are losing theirs, you obviously haven't grasped the seriousness of the situation
 
MatDavies,

I believe it is possible to screen scrape a Telnet or other emulator session. If the VB application references a certain emulator dll (hlapi.dll for Telnet), it's properties, methods, and events can be used.

However, my problem is that the company want to take this further and scrape other windows programs.

Thanks for the system hook information. I'll look into this.



 
MatDavies,

I checked the system hook you recommended.

For your information, it's certainly a useful piece of software and does record the handles of windows that are activated, closed or re-sized.

Unfortunately (for me), it does not record changes to windows (e.g. when the user enters text) which may not be possible anyway. Nor does it work under XP (I tested it under ME and XP). I have asked for help on this.
 

Have you ever seen SPY++? You may be able to replicate that functionality or use EnumWindows and EnumChildWindows to get to the handle of the edit control (text box) in question. Once you have the handle you can use either GetWindowText or perhaps SendMessage with WM_GETTEXT as the wMSG.

croydon, have you read FAQ222-2244 item 15 yet?

Good Luck

 
I also don't see any reason you can't examine all the windows currently active on the computer until you find the one you want. Then you can use a timer (for example a form timer or a windows timer connnecte to a callback function), to examine the window you want and see if its contents have changed.

Every control is actually a window, so it's just a matter of finding the one you want and reading the text out of it. If it is a graphic control, you should be able to lift the image and compare to see when it has changed.

Automatic buttonpusher programs do this, as well as SPY++ which vb5prgrmr mentioned.

So to answer your specific questions:

• Yes I believe it is possible to get some information about the active window, if not all of it.

• You can read the window name from every window, and pretty definitely identify which windows are which. For example, the IE window I'm using now ends with "Microsoft Internet Explorer." Keep in mind that nothing stops someone from naming their own application the exact same thing, but I suppose this is unlikely to occur.

• By "when the active window changes" I thought you meant when the content of the active window changes, but now I realize you might be meaning when a new window becomes active. My answer is yes, but you will have to find out on your own. I do not believe that there is a way to "hook into" the active window and be notified of when it loses focus... you'd have to check every x milliseconds to see if it is still the active window.
 
Thanks for the replies. I was not able to run Spy++ (I assume I need C++) but I think I get the idea of what it does.

The SystemHook program mentioned by MatDavies is good in that it indicates when a window becomes active (displays the handle). At present though, it does not seem to work with XP.

ESquared, with regard to your last point, my fault, I don't think I made myself clear. I would like to know when the user makes changes in the window. Here is an example scenario and what I need to do:

The user is running an AS/400 session under Telnet. They enter some information (e.g. Customer no) and press the Enter key. A new AS/400 screen will appear in the emulator. If the AS/400 program number (say line-1 column-6) is in my database table I will look up some other table and display that information in a pop-up window.

My problem now is identifying whether the content of the window has changed.

I suppose this could be done by using a timer to read and store the current content and compare it to the next read. I would guess though that there would be an overhead here that may slow down (and irritate) the user. Ideally I would like some windows indicator that flags "Content Changed!"

Again, thanks for your help.




 
I do not believe there is such an indicator, sorry.

However, unless the computers the users are on are very slow, checking every tenth of a second shouldn't be a noticeable overhead...

For what it's worth, I did some automation things with an AS/400 emulator a few years ago. I was lucky enough to find that the emulator had an implementation of VB-something and was able to automate large chunks of data entry that had previously been manual. It was a dream come true, just about. Maybe the emulator you are using might have something similar? You'd still have to check every X milliseconds, but reading the window contents might be less of a chore.
 
ESquared, thanks for that. Obviously I hope any overhead will be small. It may be that I can just store and check the AS/400 program number, rather than the whole page.

With regard to the emulator software, one is Telnet (I don't yet know the distibutor or version) and the other is JBA Explorer.
 
Croydon, you can try looking at a program called OZEXE. It has screen scraping functionality and should do what you are looking for. It was created by the former founder of Tracer Research who designed the TracerX programming interface.

you can find it at ozexe.com

Jake
 
Thanks Jake007. Unfortunately a bit expensive though at $595 per license.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top