16,472
社区成员
发帖
与我相关
我的任务
分享
HBITMAP CopyScreenToBitmap(CRect &Rect,HWND hwnd)
{
HDC hScrDC, hMemDC;
HBITMAP hOldBitmap,hBitmap;
int xScrn, yScrn;
// to screen coordinates.
MapWindowPoints(hwnd,NULL,(POINT *)&Rect,2);
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);
//
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//
if (Rect.left < 0) Rect.left = 0;
if (Rect.top < 0) Rect.top = 0;
if (Rect.right > xScrn) Rect.right = xScrn;
if (Rect.bottom > yScrn) Rect.bottom = yScrn;
//
hBitmap = CreateCompatibleBitmap(hScrDC, Rect.Width(),Rect.Height());
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC,0,0,Rect.Width(),Rect.Height(),hScrDC,Rect.left,Rect.top,SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hMemDC,hOldBitmap);
//
DeleteDC(hScrDC);
DeleteDC(hMemDC);
//
return hBitmap;
}