From 6f00ec2fb2b810392aaf817a5ab2cb1716a07cc1 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 16 Oct 2010 03:51:42 +0000 Subject: [PATCH] HWND of "active" captures the active window --- Changes | 4 ++++ MANIFEST | 3 +++ Makefile.PL | 2 +- Screenshot.pm | 22 ++++++++++++++++++++++ Screenshot.xs | 5 ++++- svwin32.c | 20 ++++++++++++++++++++ svwin32.h | 13 +++++++++++++ typemap | 5 +++++ 8 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 svwin32.c create mode 100644 svwin32.h create mode 100644 typemap diff --git a/Changes b/Changes index 06aa8ee..aa59333 100755 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ +0.009_002 + +- multiple monitor support for Win32 + 0.009_001 11 Cot 2010 - add Darwin (Apple Mac OS X) support diff --git a/MANIFEST b/MANIFEST index e4b7769..2206ce7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -13,6 +13,9 @@ Screenshot.xs Interface to C code scdarwin.c Darwin implementation scwin32.c Win32 implementation scx11.c X11 implementation +svwin32.c Win32 translate SV to HWND +svwin32.h Win32 translate SV to HWND (header) +typemap Type conversion t/00load.t Test - can we load the modules t/10win32.t Test - win32 implementation t/20x11.t Test - X11 implementation diff --git a/Makefile.PL b/Makefile.PL index b1f9a8b..50cf6f8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -34,7 +34,7 @@ if (find_header('windows.h', "Win32 header") || check_lib(header => "windows.h", lib => "gdi32", title => "Win32")) { - push @objs, 'scwin32.o'; + push @objs, 'scwin32.o', 'svwin32.o'; push @cflags, '-DSS_WIN32'; if ($^O eq 'cygwin') { push @lflags, '-L/usr/lib/w32api', '-lgdi32'; diff --git a/Screenshot.pm b/Screenshot.pm index 7f6572d..beecbc9 100644 --- a/Screenshot.pm +++ b/Screenshot.pm @@ -180,12 +180,34 @@ Currently the image is always returned as a 24-bit image. =item screenshot hwnd => I, decor => +=item screenshot hwnd => "active" + Retrieve a screenshot under Win32, if I is zero, capture the desktop. By default, window decorations are not captured, if the C parameter is set to true then window decorations are included. +As of 0.010 hwnd can also be C<"active"> to capture the active (or +"foreground") window. + +=item screenshot hwnd => 0 + +Retrieve a screeshot of the default desktop under Win32. + +=item screenshot hwnd => 0, display => -1 + +Retrieve a screenshot of all attached monitors under Win32. + +Note: this returns an image with an alpha channel, since there can be +regions in the bounding rectangle of all monitors that no particular +monitor covers. + +=item screenshot hwnd => 0, display => I + +Retrieve a screenshot from a particular monitor under Win32. A +I of zero is always treated as the primary monitor. + =item screenshot id => I =item screenshot id => I, display => I diff --git a/Screenshot.xs b/Screenshot.xs index 93d794c..d908364 100644 --- a/Screenshot.xs +++ b/Screenshot.xs @@ -5,6 +5,9 @@ #include "imext.h" #include "imperl.h" #include "imss.h" +#ifdef SS_WIN32 +#include "svwin32.h" +#endif DEFINE_IMAGER_CALLBACKS; @@ -18,7 +21,7 @@ PROTOTYPES: DISABLE Imager::ImgRaw imss_win32(hwnd, include_decor = 0, left = 0, top = 0, right = 0, bottom = 0, display = 0) - unsigned hwnd + SSHWND hwnd int include_decor int left int top diff --git a/svwin32.c b/svwin32.c new file mode 100644 index 0000000..f992793 --- /dev/null +++ b/svwin32.c @@ -0,0 +1,20 @@ +#include "svwin32.h" + +SSHWND +hwnd_from_sv(pTHX_ SV *sv) { + SvGETMAGIC(sv); + + if (SvPOK(sv)) { + STRLEN len; + char const *p = SvPV_nomg(sv, len); + + if (len == 6 && strEQ(p, "active")) { + return (SSHWND)GetForegroundWindow(); + } + else { + return (SSHWND)NULL; + } + } + + return SvUV_nomg(sv); +} diff --git a/svwin32.h b/svwin32.h new file mode 100644 index 0000000..61b4f6e --- /dev/null +++ b/svwin32.h @@ -0,0 +1,13 @@ +#ifndef SVWIN32_H +#define SVWIN32_H + +#include "EXTERN.h" +#include +#include "perl.h" + +typedef unsigned SSHWND; + +SSHWND +hwnd_from_sv(pTHX_ SV *sv); + +#endif diff --git a/typemap b/typemap new file mode 100644 index 0000000..57e04cb --- /dev/null +++ b/typemap @@ -0,0 +1,5 @@ +SSHWND T_HWND + +INPUT +T_HWND + $var = hwnd_from_sv(aTHX_ $arg); -- 2.30.2