Solved

Capturing Screen Data from Multiple Monitors

Posted on 2003-12-01
8
3,018 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now