update to a less ancient Devel::CheckLib
[imager-screenshot.git] / examples / win32_fw.pl
CommitLineData
0ddb7051
TC
1#!perl -w
2use strict;
3use Win32::API;
4use Imager;
5use Imager::Screenshot 'screenshot';
6
7# delay so I can bring the window to the front
8sleep 2;
9
10# get the API
11my $find_window = Win32::API->new('user32', 'FindWindowA', 'NP', 'N')
12 or die "Cannot import FindWindow\n";
13
14# get the window, this requires an exact match on the window title
15my $hwnd = $find_window->Call(0, "use Perl: All the Perl that's Practical to Extract and Report - Mozilla Firefox");
16
17$hwnd
18 or die "Mozilla window not found";
19
20# take a picture, including the border and title bar
21my $img = screenshot(hwnd => $hwnd, decor=>1)
22 or die Imager->errstr;
23
24# and save it
25$img->write(file=>'mozilla.ppm')
26 or die $img->errstr;
27