|
From: Vlada D. <dj...@im...> - 2003-06-20 10:29:17
|
Hi.
In this piece of code, I try to load bitmap image from a file and display it
in a window. When I run the program, nothing happens. After the call to
LoadImage(), I call the error() function, which calls GetLastError() and
displays a message box with error description. In this way, I receive a
message "Not enough storage is available to process this command". Now, I'm
not sure if there something wrong with the code, or I realy run out of
memory (which I doubt). My computer is Pentium 2 with 128 MB RAM and 20GB
hard drive. This code is actually the only code in this program, except for
standard Windows code, so I don't think there should be any memory leak. Can
you tell me if the code is OK?
P.S. I should also say that there's no message "Could not load image", so I
guess the bitmap handle is valid?
How can that be if LoadImage() could not be completed?
---------------------
LPTSTR szFileName=TEXT("bitmapa.bmp");
HBITMAP
hBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),szFileName,IMAGE_BITMAP,0,0
,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
error(); //this function calls GetLastError() and displays a
message box
if(!hBitmap)
MessageBox(hwnd,"Could not load image","Error",MB_OK);
BITMAP bmp;
GetObject(hBitmap,sizeof(BITMAP),&bmp);
PAINTSTRUCT ps;
HDC hDC=BeginPaint(hwnd,&ps);
HDC memDC=CreateCompatibleDC(hDC);
SelectObject(memDC,hBitmap);
BitBlt(hDC,0,0,bmp.bmWidth,bmp.bmHeight,memDC,0,0,SRCCOPY);
DeleteDC(memDC);
EndPaint(hwnd,&ps);
-------------------------------------
------------
Vlada
|