Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by bmann (Priest)
on Sep 20, 2005 at 23:29 UTC ( [id://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

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 ?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-26 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found