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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Window text

Status
Not open for further replies.

dgpkm

IS-IT--Management
Joined
Sep 5, 2006
Messages
2
Location
US
On Windows XP I need a way to be able get the text from a window in a loop, preferably just the last line of text, or if not just the last line, then to get all the text and compare it to the last time it went through and check for changes.

The goal is to have the script running all the time and when the text changes in the window to make a noise or send an email or something so that I can know that a new line was entered and what it was.

Unfortionately Im not the best programmer around and havent been able to get the text from the window in the first place, and theres no way I know of to get it (its not a command line program so I cant redirect its output or anything that I know of). The rest Im fairly sure I can do, but I could use help getting started.

Thanks
 
Try Win32::GuiTest. You can install it through PPM.

Here's a quick test to dissect certain windows and find all the text thats available for it.

Code:
use Win32::GuiTest qw(:ALL);

# Find all AIM conversation windows
my @windows = FindWindowLike ('','Instant Message','');

# (the middle argument there is a
# regular expression, you could also
# do things such as this...)
# FindWindowLike ('','(.+) - Notepad','')
# FindWindowLike ('','^Perl - Getting Window Text - Microsoft Internet Explorer provided by (.+)$','')

# Anyway, loop through each window that
# matched the regexp /Instant Message/
foreach my $win (@windows) {
   # Get the window's title.
   my $title = GetWindowText ($win);

   print "$win> $title\n";
   # prints like "4342> SmarterChild : Kirsle - Instant Message"
   # $win is the window ID

   # Get this window's child windows.
   my @children = GetChildWindows($win);

   # loop through each child
   foreach my $child (@children) {
      # some children can do GetWindowText to get their data,
      # others require WMGetText. So we'll get both.
      my $text = GetWindowText($child);
      my $wm   = WMGetText($child);

      print "\t$child> $text; $wm\n";
   }
}

And that should print out the details on every window with "Instant Message" in its title, as well as the text of every sub-window (which would include the different text fields on it, different buttons, sometimes the menu bars, etc.)

Win32::GuiTest can't get all the window text from all types of windows. You'll have to experiment with it. For example, I wrote an AIM convo logger in Perl doing this, by getting the AIM window children to find the conversation window and saving its text. But I can't make a logger for Windows Live Messenger because its windows don't return any useful text.

This should get you started at least. Good luck!
 
I tried it, but im not really having any luck. Its just returning a blank line.
I used WinSpy++ to get the handle and have it hardcoded, The stuff I need is in a child window which is an edit box. It also doesnt copy using WinSpy++'s capture option.

Before I go much further in wrestling with this, I think I saw in the documentation that WMGetText only has a 64k limit, is that true?
I can get the contents with AutoIt's WinGetText function, but that only has a 64k limit, and that was something I was hoping to get around, and if Win32::GuiTest doesn't have a higher limit, I'll just try and get it to work with AutoIt to put it into a text file and then use perl to do the rest.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top