|
From: Krzysztof 'S. K. <sa...@ze...> - 2003-06-20 11:49:29
|
Hello Vlada,
Friday, June 20, 2003, 12:27:55 PM, you wrote:
VD> Hi.
VD> In this piece of code, I try to load bitmap image from a file and display it
VD> in a window. When I run the program, nothing happens. After the call to
VD> LoadImage(), I call the error() function, which calls GetLastError() and
VD> displays a message box with error description. In this way, I receive a
VD> message "Not enough storage is available to process this command". Now, I'm
VD> not sure if there something wrong with the code, or I realy run out of
VD> memory (which I doubt). My computer is Pentium 2 with 128 MB RAM and 20GB
VD> hard drive. This code is actually the only code in this program, except for
VD> standard Windows code, so I don't think there should be any memory leak. Can
VD> you tell me if the code is OK?
VD> P.S. I should also say that there's no message "Could not load image", so I
VD> guess the bitmap handle is valid?
VD> How can that be if LoadImage() could not be completed?
VD> -------------------------------------
VD> ------------
VD> Vlada
I don't know what's wrong with you code, because it works on my machine :)
But I changed it a bit - look there:
(i putted it into WindowProcedure)
HBITMAP hBitmap;
LPTSTR szFileName = TEXT("bitmapa.bmp");
BITMAP bmp;
HBITMAP hOldBMP;
PAINTSTRUCT ps;
HDC hDC;
HDC memDC;
switch (message) /* handle the messages */
{
case WM_PAINT:
hBitmap =(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName,
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hBitmap)
{
GetObject(hBitmap, sizeof(BITMAP), &bmp);
hDC = BeginPaint(hwnd, &ps);
memDC = CreateCompatibleDC(hDC);
hOldBMP = (HBITMAP)SelectObject(memDC, hBitmap);
BitBlt(hDC, 0, 0, bmp.bmWidth, bmp.bmHeight, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, hOldBMP);
DeleteDC(memDC);
EndPaint(hwnd, &ps);
DeleteObject(hBitmap);
}
else
{
// you could get additional info about error here
// using GetLastError()
MessageBox(hwnd, "Could not load image", "Error", MB_OK);
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
Check if your "bitmapa.bmp" file is inside default program directory...
--
Best regards,
Krzysztof
mailto:sa...@op...
http://www.saveman.w.pl
|