int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, int nResID) { HDC hSrcDC; // source DC - memory device context HDC hDestDC; // destination DC - surface device context HBITMAP hbitmap; // handle to the bitmap resource BITMAP bmp; // structure for bitmap info int nHeight, nWidth; // bitmap dimensions
// first load the bitmap resource if ((hbitmap = (HBITMAP)LoadImage(hinstance, MAKEINTRESOURCE(nResID), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL) return(FALSE);
// create a DC for the bitmap to use if ((hSrcDC = CreateCompatibleDC(NULL)) == NULL) return(FALSE);
// select the bitmap into the DC if (SelectObject(hSrcDC, hbitmap) == NULL) { DeleteDC(hSrcDC); return(FALSE); }
// get image dimensions if (GetObject(hbitmap, sizeof(BITMAP), &bmp) == 0) { DeleteDC(hSrcDC); return(FALSE); }
nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
// retrieve surface DC if (FAILED(lpdds->GetDC(&hDestDC))) { DeleteDC(hSrcDC); return(FALSE); }
// copy image from one DC to the other if (BitBlt(hDestDC, xDest, yDest, nWidth, nHeight, hSrcDC, 0, 0, SRCCOPY) == NULL) { lpdds->ReleaseDC(hDestDC); DeleteDC(hSrcDC); return(FALSE); }
// kill the device contexts lpdds->ReleaseDC(hDestDC); DeleteDC(hSrcDC);
// return success return(TRUE); } |