NAME

Win32::Capture - Capature Win32 screen with lightweight 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 part 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 package is similar to Win32::Screenshot, also using Win32 API function, but with Image Process in Win32::GUI::DIBitmap to let you capture the screen, a window or a part of it. The Capture*(...) functions returns a new Win32::GUI::DIBitmap object which you can easily use to modify the screenshot or to store it in the file.

Screen capture functions

All these functions return a new Win32::GUI::DIBitmap object on success or undef on failure. These function are exported by default.

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

Captures part of the screen. The [0, 0] coordinate is the upper-left corner of the screen. The [$x, $y] defines the the upper-left corner of the rectangle to be captured.

CaptureScreen( )

Captures whole screen including the taskbar.

CaptureWindow( $HWND , $sec , $flag )

Captures whole window including title and border or only for Client Window. The second parameter is how many time wait for the Window be Changed to Top.

TIPS: You can using FindWindowLike to find the HWND.

flag = 0 : All the window is capture (with border)
flag = 1 : Only the Client window is capture
CaptureWindowRect( $HWND , $sec , $x, $y, $width, $height )

Captures a part of the window. Pass the window handle with the function parameter. The second parameter is how many time wait for the Window be Changed to Top.

TIPS: You can using FindWindowLike to find the HWND element(s).

Capturing helper functions

Functions for find the Window HWND to capture.

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

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

The parameter is a part of window title, and FindWindowLike will Return an Array including HWND.

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

INSTALL With ActiveState PPM

ppm install http://kenwu.idv.tw/Win32-Capture.ppd

AUTHOR

Lilo Huang

kenwu@cpan.org

http://blog.yam.com/kenwu/

COPYRIGHT AND LICENSE

Copyright 2006 by Lilo Huang All Rights Reserved.

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