in reply to How can I fetch text from Windows Title Bars?

Hi Ritter,

Here's a working start using Win32::API and Win32::API::Callback to handle EnumWindows. Error handling is up to you ;)

use strict; use warnings; use Win32::API; use Win32::API::Callback; my $getwindowtext = Win32::API->new( 'user32', 'GetWindowText', 'NPN', + 'N' ); my $enumwindows = Win32::API->new( 'user32', 'EnumWindows', 'KN', 'N' +); my $title = shift || "Mozilla"; $title = qr/\Q$title\E/i; my $cb = Win32::API::Callback-> new( sub { my $hwnd = shift; my $text = " " x 255; my $length = $getwindowtext->Call( $hwnd, $text, 255 ); $text = substr( $text, 0, $length ); if ( $text =~ $title ) { print "$text\n"; } 1; }, "NN", "N", ); my $ret = $enumwindows->Call( $cb, 0 );
Results:
C:\S>perl enumwin.pl Mozilla Command Prompt - perl enumwin.pl Mozilla preview page - Mozilla Firefox

Replies are listed 'Best First'.
Re^2: How can I fetch text from Windows Title Bars?
by Ritter (Sexton) on Sep 21, 2005 at 21:57 UTC
    The code works terrifically wonderful, thank you very much, bmann!

    And thanks you others for your suggestions of modules to use for this and similar tasks...

    Ritter
Re^2: How can I fetch text from Windows Title Bars?
by Ice-Breaker (Novice) on Jan 06, 2012 at 02:49 UTC
    WOW, thats cool :) I'm wondering if it can be done remotely with some sort of WMI interaction what do you think ?