bitmap function

Started by
0 comments, last by omegasyphon 23 years, 1 month ago
on the following bitmap function how would i make it so that it loads in an external file like bitmap.bmp instead of as a resource. are the changes i made correct?
  

int Load_Bitmap(char *name, int x, int y, LPDIRECTDRAWSURFACE7 dest_surface)
{
	HBITMAP hbitmap = NULL;
	BITMAP bmp;
	HDC image_dc, surface_dc;

// added LR_LOADFROMFILE

	// load bitmap resource

	if (!(hbitmap = (HBITMAP)LoadImage(hinstance, name,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION)))
		return(FALSE);

	// create device context for image

	if (!(image_dc = CreateCompatibleDC(NULL)))
		return(FALSE);

	// select bitmap into the DC

	if (!(SelectObject(image_dc, hbitmap)))
		return(FALSE);

	// get surface device context

	if (FAILED(dest_surface->GetDC(&surface_dc)))
		return(FALSE);

	// get image dimensions

	GetObject(hbitmap, sizeof(BITMAP), &bmp);
    int dx = bmp.bmWidth;
    int dy = bmp.bmHeight;

	// copy image to surface

	if (!(BitBlt(surface_dc, x, y, dx, dy, image_dc, 0, 0, SRCCOPY)))
		return(FALSE);
	
	// get rid of all that stuff we used

	dest_surface->ReleaseDC(surface_dc);
	DeleteDC(image_dc);
	DeleteObject(hbitmap);

	return(TRUE);
}

  
Advertisement
Yes... I also had this same question. For the answer I looked into the Microsoft DD7 header files "ddutil.h".

This is the snippet of code that you use to open a bitmap...
     // load bitmap resource	   if (!(hbitmap = (HBITMAP)               LoadImage(hinstance, name,IMAGE_BITMAP, 0, 0,                  LR_LOADFROMFILE | LR_CREATEDIBSECTION)))		return(FALSE);  


and here is the better snippet...


  //  Try to load the bitmap as a resource, if that fails, try it as a file    hbitmap = (HBITMAP) LoadImage( hInstance, name,                                 IMAGE_BITMAP, 0, 0,                                 LR_CREATEDIBSECTION );    if( hbitmap == NULL )    {        hbitmap = (HBITMAP) LoadImage( NULL, name,                                     IMAGE_BITMAP, 0, 0,                                     LR_LOADFROMFILE | LR_CREATEDIBSECTION );        if( hbitmap == NULL )		{  MessageBox(hWnd,"    Could not load the specified bitmap from file or from the resource file.    ", "DirectDraw Error: Surface Creation",MB_ICONERROR);  return FALSE;  }    }  


First... this code tries to open the "name" string as a resource... but if the hbitmap == NULL then it tries to open it as an actual file.

I hoped this helped. I am new to the whole game programming thing.

This topic is closed to new replies.

Advertisement