Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

help loading a bitmap

This topic is 6621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why don't you just use the normal bitmap loading function that comes with the DX7 SDK?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ok! guys this a new big problem..
when not!
anyway I'm trying to load a bitmap with LoadImage but always it gives me the same problem with the memory when I try to create a surface. here's the code:
LPDIRECTDRAWSURFACE4 CargaBitmap(LPCTSTR file, int dw,int dh)
{
HBITMAP hbitmap;
BITMAP bitmap;
DDSURFACEDESC2 superf;
IDirectDrawSurface4* superficie;

//carga el bitmap
hbitmap = (HBITMAP) LoadImage(NULL,file,
IMAGE_BITMAP,//PUEDE SER UN CURSOR O UN ICONO
dw,dh,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);//FLAGS PARA COMO CARGAR EL BITMAP
// coje el tamaño del bitmap
GetObject(hbitmap,sizeof(bitmap),&bitmap);
//crea una superficie para este bitmap
ZeroMemory(&superf,sizeof(superf));
superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
superf.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
superf.dwWidth = bitmap.bmWidth;
superf.dwHeight = bitmap.bmHeight;
if(lpdd4->CreateSurface(&superf,&superficie,NULL)!=DD_OK)
return NULL;


CopiaBitmap(superficie,hbitmap,0,0,0,0);
DeleteObject(hbitmap);
return superficie;

}

HRESULT CopiaBitmap(LPDIRECTDRAWSURFACE4 superficie,HBITMAP hbitmap, int x, int y, int dx, int dy)
{
HDC hdcimagen;
HDC hdcsuperf;
BITMAP bitmap;
DDSURFACEDESC2 superf;
HRESULT hresult;
if (hbitmap == NULL | | superficie == NULL)
return E_FAIL;

superficie->Restore();
hdcimagen = CreateCompatibleDC(NULL);
if (!hdcimagen)
OutputDebugString("no pudo crear compatible\n");
SelectObject(hdcimagen,hbitmap);
GetObject(hbitmap,sizeof(bitmap),&bitmap);
dx = dx == 0 ? bitmap.bmWidth : dx;
dy = dy == 0 ? bitmap.bmHeight : dy;

superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
superficie->GetSurfaceDesc(&superf);

if ((hresult = superficie->GetDC(&hdcsuperf)) == DD_OK)
{
StretchBlt(hdcsuperf,0,0,superf.dwWidth,superf.dwHeight,hdcimagen,x,y,dx,dy,SRCCOPY);
superficie->ReleaseDC(hdcsuperf);
}
DeleteDC(hdcimagen);
return hresult;
}

sorry for the long code, the problem is always in the CreateSurface funtion.
I appreciate the way you guys help me in the past and will appreciate any help now

thanks
_José

Share this post


Link to post
Share on other sites