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);
}
bitmap loading function
i was reading the game programming genesis article and he says
you could convert the following bitmap loading function to use
external files so does anyone know how to make the function load external files?
Pass a string rather than a resource ID (you can use an optional extra parameter), and use this in LoadImage, and have the LR_LOADFROMFILE (If I remember correctly) flag along with LR_CREATEDIBSECTION, and I think hInstance can be null.
Look up the LoadImage function because that''s the one that does the loading.
Look up the LoadImage function because that''s the one that does the loading.
so is this correct:
change
change
int LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest, int nResID)toint LoadBitmapResource(LPDIRECTDRAWSURFACE7 lpdds, int xDest, int yDest,char *bitmap)andif ((hbitmap = (HBITMAP)LoadImage(hinstance, MAKEINTRESOURCE(nResID), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL)toif ((hbitmap = (HBITMAP)LoadImage(hinstance,bitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement