今天写了一个函数为把两图片合并,并且可以循环添加图片,但是出现错误,看了半天还是找不出来,大虾们帮忙看看
HBITMAP CMainFrame::AddCopyScreenToBitmap(LPRECT lpRect)
{
ShowWindow(SW_SHOW);
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 hBitmap1 = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
//ShowWindow(SW_HIDE);
BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY);
hBitmap1 =(HBITMAP)SelectObject(hMemDC, hOldBitmap);
BITMAP bm;
GetObject( hBitmap, sizeof(BITMAP), &bm);
HDC hdc = CreateDC(_T("DISPLAY1"), NULL, NULL, NULL);
HDC hSrcDC1 = CreateCompatibleDC(hdc);
HDC hSrcDC2 = CreateCompatibleDC(hdc);
HBITMAP hbm = CreateCompatibleBitmap(hdc,nWidth,bm.bmHeight + nHeight);
hOldBitmap = (HBITMAP)SelectObject(hdc,hbm);
SelectObject(hSrcDC1,hBitmap);
SelectObject(hSrcDC2,hBitmap1);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hSrcDC1,0,0,SRCCOPY);
BitBlt(hdc,0,0,nWidth,nHeight,hSrcDC2,0,0,SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hdc,hOldBitmap);
DeleteDC(hSrcDC1);
DeleteDC(hSrcDC2);
DeleteDC(hdc);
DeleteObject(hbm);
DeleteDC(hScrDC);
DeleteDC(hMemDC);
ShowWindow(SW_SHOW);
return hBitmap;
}