静态屏幕截图

时间:2022-01-01 15:23:18

静态屏幕截图void CCaputretestDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 RECT rect;
 rect.left=0;
 rect.top=0;
 rect.right=200;
 rect.bottom=200;
 CopyScreenToBitmap(&rect);
}

HBITMAP CCaputretestDlg::CopyScreenToBitmap(LPRECT lpRect)
{
 HDC       hScrDC, hMemDC;     
 HBITMAP    hBitmap, hOldBitmap;  
 int       nX, nY, nX2, nY2;     
 int       nWidth, nHeight;
 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
 hMemDC = CreateCompatibleDC(hScrDC);
 nX = lpRect->left;
 nY = lpRect->top;
 nX2 = lpRect->right;
 nY2 = lpRect->bottom;
 nWidth = nX2 - nX;
 nHeight = nY2 - nY;
 hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
 hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
 BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY);
 hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
 DeleteDC(hScrDC);
 DeleteDC(hMemDC);
 if (OpenClipboard())
 {
  EmptyClipboard();
  SetClipboardData(CF_BITMAP, hBitmap);
  CloseClipboard();
 }
 return hBitmap;
}

屏幕拷贝到了剪切板,可到画图程序中ctrl+v查看,如果要保存,请自己添加程序

参考:http://www.vckbase.com/document/viewdoc/?id=1671QQ 静态截图程序模拟实现
VC知识库在线杂志,第48期,QQ 静态截图完善实现之改造 CRectTracker 类,QQ 静态截图程序模拟实现