help loading a bitmap
-ns
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é