|
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
|
|
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
|
|
From: Vlada D. <dj...@im...> - 2003-06-20 12:24:12
|
----- Original Message -----
From: "Krzysztof 'Saveman' Kapuscik" <sa...@ze...>
To: <dev...@li...>
Sent: Friday, June 20, 2003 1:48 PM
Subject: Re: [Dev-C++] display bitmap
> 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
>
>
I got it working now. The thing is that I was using the code in response to
WM_LBUTTONDOWN message, and now I changed it to use GetDC() for obtaining
device context instead of BeginPaint(). Thanks for help, guys.But would like
to now why I was getting that strange error. I can't believe it's that wrong
to use BeginPaint() outside the WM_PAINT message?
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: INetU
> Attention Web Developers & Consultants: Become An INetU Hosting Partner.
> Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
> INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Krzysztof K. <sa...@op...> - 2003-06-20 12:34:14
|
Hello Vlada,
Friday, June 20, 2003, 2:23:39 PM, you wrote:
VD> ----- Original Message -----
VD> From: "Krzysztof 'Saveman' Kapuscik" <sa...@ze...>
VD> To: <dev...@li...>
VD> Sent: Friday, June 20, 2003 1:48 PM
VD> Subject: Re: [Dev-C++] display bitmap
>> 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
VD> display it
>> VD> in a window. When I run the program, nothing happens. After the call
VD> to
>> VD> LoadImage(), I call the error() function, which calls GetLastError()
VD> and
>> VD> displays a message box with error description. In this way, I receive
VD> a
>> VD> message "Not enough storage is available to process this command".
VD> 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
VD> 20GB
>> VD> hard drive. This code is actually the only code in this program,
VD> except for
>> VD> standard Windows code, so I don't think there should be any memory
VD> 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",
VD> 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,
VD> 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,
VD> 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
VD> queue */
>> break;
>> default: /* for messages that we don't deal
VD> 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
>>
>>
VD> I got it working now. The thing is that I was using the code in response to
VD> WM_LBUTTONDOWN message, and now I changed it to use GetDC() for obtaining
VD> device context instead of BeginPaint(). Thanks for help, guys.But would like
VD> to now why I was getting that strange error. I can't believe it's that wrong
VD> to use BeginPaint() outside the WM_PAINT message?
From MSDN:
An application should not call BeginPaint except in response
to a WM_PAINT message. Each call to BeginPaint must have a
corresponding call to the EndPaint function.
--
Best regards,
Krzysztof
mailto:sa...@op...
http://www.saveman.w.pl
|
|
From: <gen...@ya...> - 2003-06-23 01:52:31
|
Hi out there, i'm a fresh Win32 programmer. i have a problem - how do you display images that are not natively bitmaps in Win32 ? i have the imagelib devpak - so i can read PNG, & JPEG images, but how do you dispplay them? in windows, and generically? thanx ________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://uk.messenger.yahoo.com/ |
|
From: staale <st...@le...> - 2003-06-25 22:05:28
|
Hi all, Is there a DevPak repository where we can post (get..:o) DevPak's? Best Regards Staale |
|
From: Colin L. <ha...@bl...> - 2003-06-29 14:20:26
|
Hi, We are working on it, through a new site for Dev-C++. Hopefully we should finish it soon :) Greetings, Colin On Thursday 26 June 2003 00:12, you wrote: > Hi all, > > Is there a DevPak repository where we can post (get..:o) DevPak's? > > Best Regards > Staale > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: INetU > Attention Web Developers & Consultants: Become An INetU Hosting Partner. > Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! > INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |