#include "mdx.h" IDirectDrawSurface* DDLoadBitmap(IDirectDraw* pdd, LPCSTR szBitmap) { HBITMAP hbm; BITMAP bm; IDirectDrawSurface *pdds; // Load Image for loading from Disk hbm = (HBITMAP)LoadImage(NULL, szBitmap, IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hbm == NULL) { return NULL; } GetObject(hbm, sizeof(bm), &bm); // size // Create Surface for this Bitmap pdds = CreateOffScreenSurface(pdd, bm.bmWidth,bm.bmHeight); if(pdds) { DDCopyBitmap(pdds, hbm, bm.bmWidth,bm.bmHeight); } DeleteObject(hbm); return pdds; } // this is a surface when can be cliped IDirectDrawSurface* CreateOffScreenSurface(IDirectDraw* pdd, int dx, int dy) { DDSURFACEDESC ddsd; IDirectDrawSurface* pdds; // Create Surface for this bitmap ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = dx; ddsd.dwHeight = dy; if(pdd->CreateSurface(&ddsd, &pdds,NULL) != DD_OK) { return NULL; } else { return pdds; } } // Copy Bitmap HRESULT DDCopyBitmap(IDirectDrawSurface* pdds, HBITMAP hbm, int dx, int dy) { HDC hdcImage; HDC hdc; HRESULT hr; HBITMAP hbmOld; // Select Bitmap into a MemoryDC hdcImage = CreateCompatibleDC(NULL); hbmOld = (HBITMAP)SelectObject(hdcImage, hbm); if((hr = pdds->GetDC(&hdc)) == DD_OK) { BitBlt(hdc,0,0,dx,dy,hdcImage,0,0,SRCCOPY); pdds->ReleaseDC(hdc); } SelectObject(hdcImage, hbmOld); DeleteDC(hdcImage); return hr; }