#!/usr/bin/env perl use strict; use warnings; use Const::Fast; use Imager; use Imager::Screenshot qw( screenshot ); use Win32::GuiTest qw( FindWindowLike SetForegroundWindow ); const my $TYPE => 'bmp'; #my $TYPE = 'bmp'; my @windows = FindWindowLike(0, '(?:Chrome)|(?:Firefox)|(?:Opera)' ); for my $hwnd (@windows) { warn "$hwnd\n"; SetForegroundWindow $hwnd; sleep 1; my $img = screenshot(hwnd => $hwnd, decor => 1); die Imager->errstr unless $img; $img->write(file => "$hwnd.$TYPE", type => $TYPE) or die $img->errstr; }