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

相关文章:

  • 2021-06-22
  • 2022-01-12
  • 2021-05-31
  • 2021-05-26
  • 2021-08-02
  • 2021-07-20
  • 2021-05-19
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2021-11-04
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案