Solved

Capturing Screen Data from Multiple Monitors

Posted on 2003-12-01
8
3,148 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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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