//----------------------------------------------------------------------------- // Name: InitSurfaces() // Desc: This function reads the bitmap file FRNTBACK.BMP and stores half of it // in offscreen surface 1 and the other half in offscreen surface 2. //----------------------------------------------------------------------------- static BOOL InitSurfaces() { HBITMAP hbm; #if 0 // Load our bitmap resource. hbm = DDGetBitmapHandle(hInstance,szBitmap); if (hbm == NULL) return FALSE; DDCopyBitmap(g_pDDSOne, hbm, 0, 0, 640, 480); DDCopyBitmap(g_pDDSTwo, hbm, 0, 480, 640, 480); DeleteObject(hbm); #endif return TRUE; }
/* * DDLoadBitmap: * create a DirectDrawSurface from a bitmap resource. */ LPDIRECTDRAWSURFACE DDLoadBitmap(LPCSTR szBitmap, int dx, int dy) { HBITMAP hbm; BITMAP bm; DDSURFACEDESC ddsd; IDirectDrawSurface *pdds; hbm = (HBITMAP)LoadImage(NULL, szBitmap, IMAGE_BITMAP, dx, dy, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hbm == NULL) { return NULL; } // get size of the bitmap GetObject(hbm, sizeof(bm), &bm); // get size of bitmap // create a DirectDrawSurface 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 = bm.bmWidth; ddsd.dwHeight = bm.bmHeight; if (lpDD->CreateSurface(&ddsd, &pdds, NULL) != DD_OK) { return NULL; } DDCopyBitmap(pdds, hbm, 0, 0, 0, 0); DeleteObject(hbm); return pdds; }
/* * DDReLoadBitmap: * load a bitmap from a file or resource into a directdraw surface. * normaly used to re-load a surface after a restore. */ HRESULT DDReLoadBitmap(LPDIRECTDRAWSURFACE pdds, LPCSTR szBitmap) { HBITMAP hbm; HRESULT hr; hbm = (HBITMAP)LoadImage(NULL, szBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hbm == NULL) { OutputDebugString("handle is null\n"); return E_FAIL; } hr = DDCopyBitmap(pdds, hbm, 0, 0, 0, 0); if (hr != DD_OK) { OutputDebugString("ddcopybitmap failed\n"); } DeleteObject(hbm); return hr; }