VC屏幕截图代码 转

VC屏幕截图代码
2008年05月20日 14:09

HBITMAP CLinkDlg::CopyScreenToBitmap(LPRECT lpRect)
{
HDC hScrDC, hMemDC;
HBITMAP hOldBitmap;
int nX, nY, nX2, nY2;
int nWidth, nHeight;
int xScrn, yScrn;
if (IsRectEmpty(lpRect))
   return NULL;
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);
nX = lpRect->left;
nY = lpRect->top;
nX2 = lpRect->right;
nY2 = lpRect->bottom;
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
if (nX < 0) nX = 0;
if (nY < 0) nY = 0;
if (nX2 > xScrn) nX2 = xScrn;
if (nY2 > yScrn) nY2 = yScrn;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
ShowWindow(SW_HIDE);
BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hMemDC, hOldBitmap);
DeleteDC(hScrDC);
DeleteDC(hMemDC);
ShowWindow(SW_SHOW);
return hBitmap;
}

posted on 2011-09-29 17:27  carekee  阅读(807)  评论(0编辑  收藏  举报