LPDIRECTDRAWSURFACE7 DDraw_Create_Surface(int width, int height, int mem_flags){ DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE7 lpdds; DDRAW_INIT_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwWidth = width; ddsd.dwHeight = height; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags; if(FAILED(lpdd->CreateSurface(&ddsd,&lpdds,NULL))) return (NULL); DDCOLORKEY color_key; color_key.dwColorSpaceLowValue = 0; color_key.dwColorSpaceHighValue = 0; lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key); return(lpdds);}
I call this then I call the bitmap loading function in my startup code.
And here is the bitmap loading stuff.
IDirectDrawSurface7* DDLoadBitmap( IDirectDraw7* pdd, LPCSTR szBitmap, int dx, int dy){ HBITMAP hbm; BITMAP bm; DDSURFACEDESC2 ddsd; IDirectDrawSurface7 *pdds; // // Try to load the bitmap as a resource, if that fails, try it as a file // hbm = (HBITMAP) LoadImage(GetModuleHandle(NULL), szBitmap, IMAGE_BITMAP, dx, dy, LR_CREATEDIBSECTION); if (hbm == NULL) 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); // // 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 (pdd->CreateSurface(&ddsd, &pdds, NULL) != DD_OK) return NULL; DDCopyBitmap(pdds, hbm, 0, 0); DeleteObject(hbm); return pdds;}void DDCopyBitmap(LPDIRECTDRAWSURFACE7 &lpddsToCopy, // Surface to copy too HBITMAP hbm, // handle to bitmap to copy DWORD width, DWORD height) { HDC hdcImage = NULL; // use in StretchBlt() HDC hlpddsToCopy = NULL; // use in StretchBlt() //if( hbm == NULL || lpddsToCopy == NULL ) // ThrowEx(__LINE__,__FILE__); hdcImage = CreateCompatibleDC( NULL ); //if( hdcImage == NULL )// ThrowEx(__LINE__,__FILE__); SelectObject( hdcImage, hbm ); // puts bitmap handle into this // Compatible DC for use in StretchBlt if( FAILED( lpddsToCopy->GetDC( &hlpddsToCopy ))) // Get DC handle for Surface to Blt too // ThrowEx(__LINE__,__FILE__); MessageBox(main_window_handle,"error","error",NULL); if( FAILED( StretchBlt(hlpddsToCopy, // handle of destination surface 0, 0, // (x,y) of destination rect width, // Width of destination surface height, // Height of destination surface hdcImage, // handle of source surface 0, 0, // (x,y) of source surface width, // Width of source height, // Height of source SRCCOPY ))) { // SRCCOPY: Copies the source rectangle directly // to the destination rectangle// ThrowEx(__LINE__,__FILE__); }// end if lpddsToCopy->ReleaseDC(hlpddsToCopy); // To clean up GetDC(&hlpddsToCopy) DeleteDC(hdcImage);// To clean up memory device context // hdcImage = CreateCompatibleDC(NULL)}
Hibiki
Wheres the any key?
find your element
at mutedfaith.com.
<º>
[edited by - Hibiki_Konzaki on July 31, 2002 9:12:54 AM]