HWND of "active" captures the active window
authorTony Cook <tony@develop-help.com>
Sat, 16 Oct 2010 03:51:42 +0000 (03:51 +0000)
committerTony Cook <tony@develop-help.com>
Sat, 16 Oct 2010 03:51:42 +0000 (03:51 +0000)
Changes
MANIFEST
Makefile.PL
Screenshot.pm
Screenshot.xs
svwin32.c [new file with mode: 0644]
svwin32.h [new file with mode: 0644]
typemap [new file with mode: 0644]

diff --git a/Changes b/Changes
index 06aa8ee3bf8c0edc07f9100aa1c9a20907b0396b..aa59333c6e4a07c7edde9da310e329353e049e3d 100755 (executable)
--- 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
index e4b7769a26f4d65d9196c19a6f648e562e7abf38..2206ce7e89bc565feb96fed3445c7e00078b7051 100644 (file)
--- 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
index b1f9a8bea24d4578ad1d1678b3fa9bf2ec4ac04b..50cf6f88b02260e9b51951f1827f073e55559c8b 100644 (file)
@@ -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';
index 7f6572dc76784e07d6e6d9e19785b1cf192f6533..beecbc96d916d9cdcb3e4743f1229345db95b879 100644 (file)
@@ -180,12 +180,34 @@ Currently the image is always returned as a 24-bit image.
 
 =item screenshot hwnd => I<window handle>, decor => <capture decorations>
 
+=item screenshot hwnd => "active"
+
 Retrieve a screenshot under Win32, if I<window handle> is zero,
 capture the desktop.
 
 By default, window decorations are not captured, if the C<decor>
 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<index>
+
+Retrieve a screenshot from a particular monitor under Win32.  A
+I<display> of zero is always treated as the primary monitor.
+
 =item screenshot id => I<window id>
 
 =item screenshot id => I<window id>, display => I<display object>
index 93d794cc942743c9abda641fd8c69f2294307051..d908364e1585cb4bf709f4c89a83635e38c735d7 100644 (file)
@@ -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 (file)
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 (file)
index 0000000..61b4f6e
--- /dev/null
+++ b/svwin32.h
@@ -0,0 +1,13 @@
+#ifndef SVWIN32_H
+#define SVWIN32_H
+
+#include "EXTERN.h"
+#include <windows.h>
+#include "perl.h"
+
+typedef unsigned SSHWND;
+
+SSHWND
+hwnd_from_sv(pTHX_ SV *sv);
+
+#endif
diff --git a/typemap b/typemap
new file mode 100644 (file)
index 0000000..57e04cb
--- /dev/null
+++ b/typemap
@@ -0,0 +1,5 @@
+SSHWND T_HWND
+
+INPUT
+T_HWND
+       $var = hwnd_from_sv(aTHX_ $arg);