Solved

Capturing Screen Data from Multiple Monitors

Posted on 2003-12-01
8
3,060 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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