-
June 16th, 2009, 09:06 PM
#1
screen capture..
I have two monitors, So I'd like to save it for ecah monitor.
So I get monitors' handle , and DC from EnumDisplayMonitor and MonitorEnumProc.
Code:
HMONITOR hMonitorHandle[2];
HDC hdcMonitor[2];
CRect area[2];
CString filename[2] = {"firstMonitor.jpg", "secondMonitor.jpg" };
int index=0;
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,LPARAM dwData)
{
TCHAR sInfo[256];
MONITORINFOEX mi;
mi.cbSize=sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor,&mi);
//save two monior's handle and dc.
(*(LPRECT)area[iindex])=*lprcMonitor;
hMonitorHandle[index]=hMonitor;
hdcMonitor[index++]=hdcMonitor;
return TRUE;
}
//fr saving, I call CaptureScreen(...) function...
for ( int i = 0 ; i < 2 ;i++ )
{
//first screen saved succesfully... but second screen is image is black...
//I don't know why second monitor not captured..
CaptureScreen( (HWND)hMonitorHandle[i], hdcMonitor[i], area[i] , filename[i])
}
Void CaptureScreen( HWND hWnd, HDC hdc , Rect rect , CString filename)
{
HWND hDesktopWnd = hWnd;
//HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hDesktopDC = hdc ;
CRect m_rDrawingSurface;
BITMAPINFOHEADER BMIH;
HBITMAP hCaptureBitmap;
BYTE* m_pDrawingSurfaceBits;
CDC* pDC = GetDC();
if(pDC != NULL)
{
BMIH.biSize = sizeof(BITMAPINFOHEADER);
BMIH.biBitCount = 24;
BMIH.biPlanes = 1;
BMIH.biCompression = BI_RGB;
BMIH.biWidth = m_rDrawingSurface.Width();
BMIH.biHeight = m_rDrawingSurface.Height();
BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount) + 31) & ~31) >> 3) * BMIH.biHeight;
hCaptureBitmap = CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&m_pDrawingSurfaceBits, NULL, 0);
ReleaseDC(pDC);
}
//HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC,
0,
0,
m_rDrawingSurface.Width(),
m_rDrawingSurface.Height(),
hDesktopDC,0, 0,SRCCOPY|CAPTUREBLT);
SaveitToBMP(hCaptureBitmap ,filename) //Place holder...
ReleaseDC(hDesktopWnd,hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
}
Last edited by cilu; June 17th, 2009 at 12:42 AM.
Reason: code tags
-
June 16th, 2009, 10:50 PM
#2
Re: screen capture..
Is there a question somewhere in there?
Hard to see without the code tags.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 17th, 2009, 01:02 PM
#3
Re: screen capture..
I do not have second monitor attached to my system at the moment, so I can’t test this.
However, few things look odd in your code:
- you cast HMONITOR to HWND, which it isn’t
- you later assign it to local variable hDesktopWnd, which is not used in that function, except for in a call to ReleaseDC(hDesktopWnd,hDesktopDC); (but you never called GetDC() for it)
- your CDC* pDC = GetDC(); gets DC from the primary monitor, not for the one passed in; you already have HDC hdc parameter - why not use it?
- you are blitting to a hCaptureDC, but what is it?
If this is a pseudo code, there isn't much sense in looking for issues in it...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|