Solved

Capturing Screen Data from Multiple Monitors

Posted on 2003-12-01
8
3,094 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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