VC获取窗口图片(截图)

来源:互联网 发布:税务局知乎 编辑:程序博客网 时间:2024/05/02 02:01
//借鉴网上的文章:HBITMAP CopyDCToBitmap(HDC hDC, LPRECT lpRect) {  if(!hDC || !lpRect || IsRectEmpty(lpRect))   return NULL;    HDC hMemDC;    HBITMAP hBitmap, hOldBitmap;    int nX, nY, nX2, nY2;    int nWidth, nHeight;     nX = lpRect->left;  nY = lpRect->top;  nX2 = lpRect->right;  nY2 = lpRect->bottom;  nWidth = nX2 - nX;  nHeight = nY2 - nY;    hMemDC = CreateCompatibleDC(hDC);    hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight);    hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);    StretchBlt(hMemDC, 0, 0, nWidth, nHeight, hDC, nX, nY, nWidth, nHeight, SRCCOPY);    hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);     DeleteDC(hMemDC);  DeleteObject(hOldBitmap);      return hBitmap; }

0 0
原创粉丝点击