Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to capture screen under Win32?

by jplindstrom (Monsignor)
on Apr 10, 2002 at 19:12 UTC ( [id://158113]=note: print w/replies, xml ) Need Help??


in reply to How to capture screen under Win32?

Win32::GUI to the rescue.
  1. Find out the DC (device context). You can use Win32::GUI or perhaps something like Win32::ActAcc. Note: If you can find out the hwind (window handler), you can get the DC.
  2. Grab it with Win32::GUI::DIBitmap (check out the newFromDC method).

I don't think you can put images in the clipboard with Win32::Clipboard, only text.

/J

Replies are listed 'Best First'.
Re: Re: How to capture screen under Win32?
by cheshirecat (Sexton) on Apr 11, 2002 at 12:16 UTC
    Actually you can put images into Win32::Clipboard but the gotcha is that if your screen depth is set to 32bit and NOT 24bit, the resulting BMP is not valid for most apps.

    I have some ugly code to fix 32bit BMPs to 24bit, let me know if you want to see it.

    as for the code to put a screenshot into the clipboard, see below

    use strict; use Win32::OLE; use Win32::Clipboard; use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow + SendKeys); my $ie; my $image; # use existing instance if Internet Explorer is already running eval {$ie = Win32::OLE->GetActiveObject('InternetExplorer.Application' +)}; die "IE not installed" if $@; unless (defined $ie) { $ie = Win32::OLE->new('InternetExplorer.Application', sub {$_[0]->Qu +it;}) or die "Oops, cannot start IE"; } $ie->{Visible} = 1; # get the handle and use it to force IE to the foreground SetForegroundWindow($ie->HWND); # use send keys # How Do I Maximise The Current Window, Without Using The Mouse? # Press (SHIFT + ALT + SPACEBAR) then press X SendKeys("%+{SPACEBAR}{PAUSE 5}X"); # How do I get a screen grab, use Print Screen to grab entire screen # use ALT + PRTSCR to get current window or dialog NOT screen ! SendKeys("%{PRTSCR}"); $image = Win32::Clipboard::GetBitmap(); # $image now contains your .BMP

    Cheers

    Cheshire Cat

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://158113]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-03-28 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found