Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How can I fetch text from Windows Title Bars?

by bmann (Priest)
on Sep 20, 2005 at 23:29 UTC ( #493621=note: print w/ replies, xml ) Need Help??


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


Comment on Re: How can I fetch text from Windows Title Bars?
Select or Download Code
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 ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://493621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2014-08-28 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (264 votes), past polls