?
Solved

Capturing Screen Data from Multiple Monitors

Posted on 2003-12-01
8
Medium Priority
?
3,254 Views
Last Modified: 2013-12-03
I have been able to capture screen data from a single monitor using
a combination of GetDesktopWindow, GetWindowDC, and BitBlt.
This is great for a single monitor case, but I don't know what to do
for when the desktop spans across multiple monitors.
So here are the pieces I need to solve this:
1. How does my code know when a user has configured their windows computer
to use two or more monitors?  
2. How does my code know the arrangement of monitors (laid out horizonally, or vertically)
3. Most important part: Once I detect multiple monitors, how do I capture
the data off of the other monitors?

Thanks for any help.
0
Comment
Question by:bjornsone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9852266
>>but I don't know what to do for when the desktop spans across multiple monitors

The GDI should handle that in a transparent way, i.e.: There should be no difference at all.
0
 

Author Comment

by:bjornsone
ID: 9852439
I use GetWindowRect to determine what area I can capture.  
This function gives me only the rectangle of the first monitor, so
the GDI does not provide complete transparency.  How do I figure
out the coordinates on the other monitor (if it exists)?
Once I have that data, then my code can try to use the same windows
methods to capture the data from the other monitor.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9852630
>>This function gives me only the rectangle of the first monitor, so
>>the GDI does not provide complete transparency

Aww, that's poor :-(

Well, check out the MultiMon docs on MSDN. The following article is 'Painting on a DC That Spans Multiple Displays', so I guess capturing is pretty similar: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/monitor_82yb.asp

To respond to a WM_PAINT message, use code like the following.

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EnumDisplayMonitors(hdc, NULL, MyPaintEnumProc, 0);
EndPaint(hwnd, &ps);
 
To paint the top half of a window, use code like the following.

GetClient Rect(hwnd, &rc);
rc.bottom = (rc.bottom - rc.top) / 2;
hdc = GetDC(hwnd);
EnumDisplayMonitors(hdc, &rc, MyPaintEnumProc, 0);
ReleaseDC(hwnd, hdc);

To paint the entire virtual screen optimally for each monitor, use code like the following.

hdc = GetDC(NULL);
EnumDisplayMonitors(hdc, NULL, MyPaintScreenEnumProc, 0);
ReleaseDC(NULL, hdc);

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:bjornsone
ID: 9853111
I'm compiling with Visual Studio 6.0 on a Win2000 machine and I am
having problems using your suggested function of EnumDisplayMonitors
I found that it is only included in the "WinUser.h" header file if the
windows version is at least 0x0500.  I tried just redefining the value
of this but it still didn't find it.  How can I get this method to compile?
0
 
LVL 86

Expert Comment

by:jkr
ID: 9853287
Well, either use

#define _WIN32_WINNT  0x0500

before including any windows header files or

#define COMPILE_MULTIMON_STUBS
0
 

Author Comment

by:bjornsone
ID: 9853718
I still get an error of "error C2065: 'EnumDisplayMonitors' : undeclared identifier"

I tried both of the suggested preprocessor definitions you suggested.
This is my code which won't copile using the suggested method:

#define _WIN32_WINNT  0x0500

#include "stdafx.h"
#include <stdio.h>
#include "winuser.h"


BOOL CALLBACK MonitorEnumProc(
  HANDLE hMonitor,  // handle to display monitor
  HDC hdcMonitor,     // handle to monitor-appropriate device context
  LPRECT lprcMonitor, // pointer to monitor intersection rectangle
  LPARAM dwData       // data passed from EnumDisplayMonitors
)
{
  OutputDebugString("Got called");
  return TRUE;
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  HWND captureHWND=GetDesktopWindow();

  RECT winRect;
  GetWindowRect(captureHWND, &winRect);

  char S1[256];
  sprintf(S1, "Got rect %d, %d, %d, %d", winRect.left, winRect.top, winRect.right-winRect.left, winRect.bottom-winRect.top);
  OutputDebugString(S1);

  DWORD param = 42;
  EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, &param);

      return 0;
}
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 9868047
That's strange - check out the sample code from http://www.microsoft.com/msj/0697/monitor/monitor.aspx ("How to Exploit Multiple Monitor Support in Memphis and Windows NT 5.0"):

*----------------------------------------------------------------------------*\
|   TestMM.c : A test sample that calls new Multi monitor APIs and             |
|              displays the results in a simple window.                        |
|                                                                              |
\*----------------------------------------------------------------------------*/

#include <windows.h>
#include <windowsx.h>
#include "multimon.h"
#include "mmhelp.h"
#include "testmm.rc"

//
// normally you just include "multimon.h" (like above)
// but one C file needs to define COMPILE_MULTIMON_STUBS
// so the compatibility stubs will be defined
//
#define COMPILE_MULTIMON_STUBS
#include "multimon.h"
0
 

Author Comment

by:bjornsone
ID: 9868241
Thanks,
Your suggested header inclusion allowed it to compile and then
the function of EnumDisplayMonitors worked just great.

I also found a different way of getting the information
in a simple case (two horizontal monitors) at the site:
http://www.codeproject.com/cpp/multimon.asp#xx223852xx
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question