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