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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.