NAME

Win32::Capture - Capture screen and manipulate it with Win32::GUI::DIBitmap.

SYNOPSIS

use Win32::Capture;

$image = CaptureScreen(); # Capture whole screen.
$image->SaveToFile('screenshot.png');

# or

$image = CaptureRect($x, $y, $width, $height); # Capture a portion of window.
$image->SaveToFile('screenshot.png');

# or

@WIN = FindWindowLike('CPAN'); # Find the HWND to be captured.

if ($#WIN<0) {
     print "Not found";
} else {
      foreach (@WIN) {
          my $image = CaptureWindowRect($_, 2, 0, 0, 400, 300);
          $image->SaveToFile("$_.jpg", JPEG_QUALITYSUPERB);
      }
}

DESCRIPTION

The functions of package are similar to Win32::Screenshot. But you can manipulate screen shot image with Win32::GUI::DIBitmap

Screen capture functions

All of these functions are returning a new Win32::GUI::DIBitmap instance on success or undef on failure. These functions are exported by default.

CaptureRect($x, $y, $width, $height)

Capture a portion of the screen. The [0, 0] coordinate is on the upper-left corner of the screen. The [$x, $y] defines the the upper-left corner of the rectangle to be captured.

CaptureScreen()

Capture whole screen include taskbar.

CaptureWindow($HWND, $sleepTime, $flag)

Capture whole window include title and border parts, or client window region only.

TIPS: Use FindWindowLike helper function to find $HWND value.

$flag = 0 : Entire window will be captured (with border)
$flag = 1 : Only client window region will be captured.
CaptureWindowRect($HWND, $sleepTime, $x, $y, $width, $height)

Capture a portion of the window.

TIPS: Use FindWindowLike helper function to find $HWND value.

Capturing helper function

FindWindowLike($pattern)
@hwnds = FindWindowLike('CPAN');

if ($#hwnds<0) {
     print "Not found";
} else {
      foreach (@hwnds) {
          my $image = CaptureWindowRect($_, 2, 0, 0, 400, 300);
          $image->SaveToFile("$_.jpg", JPEG_QUALITYSUPERB);
      }
}

The $pattern argument stands for a part of window title. FindWindowLike will return an array with HWND elements.

SEE ALSO

Win32::Screenshot

Some documentation refer from here.

Win32::GUI::DIBitmap

The raw data from the screen are loaded into Win32::GUI::DIBitmap object. You have a lot of possibilities what to do with the captured image.

MSDN

http://msdn.microsoft.com/library

AUTHOR

Lilo Huang

COPYRIGHT AND LICENSE

Copyright 2006 by Lilo Huang All Rights Reserved.

You can use this module under the same terms as Perl itself.