From: Manuel Hoeger on 16 Feb 2010 12:33 Hi, I tried to show a png Image using CImage ( Visual Studio 2008 prof ) It works pretty good, but only in Release Mode. If I run it in Debug Mode there is a Message: "Debug Assertion Failed! Program: ....[..]\application.exe File: g:[...]\atlimage.h Line: 503 Expression: m_hbitmap == 0 [..] if I ignore the message the picture is schown. How can I avoid this Failure My Code: BOOL OK; LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio 2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png"); CRect rect; GetClientRect(&rect); CWindowDC pDC(this); CDC dc; OK=m_Image.Load(lpBitSource); dc.CreateCompatibleDC(&pDC); m_Image.Draw(pDC.m_hDC,CRect(&rect)); Thanks for answers. Manu
From: Seetharam on 16 Feb 2010 16:20 It asserts because "m_Image" already has some value from the last call. Try calling "m_Image.Destroy()" after you are done with your drawing or just before calling "m_Image.Load()" in your code above. -Seetharam
From: Tom Serface on 16 Feb 2010 22:57 To add to the other posts... You will want to support any images that you create with the CImage class (or any other GDI+ functions) otherwise you will get resource leaks. Tom "Manuel Hoeger" <Manuel.Hoeger(a)physik.stud.uni-erlangen.de> wrote in message news:7u037sFup1U1(a)mid.dfncis.de... > Hi, > > I tried to show a png Image using CImage ( Visual Studio 2008 prof ) > > It works pretty good, but only in Release Mode. If I run it in Debug Mode > there is a Message: > > "Debug Assertion Failed! > Program: ....[..]\application.exe > File: g:[...]\atlimage.h > Line: 503 > > Expression: m_hbitmap == 0 > [..] > > > if I ignore the message the picture is schown. How can I avoid this > Failure > > My Code: > > BOOL OK; > LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio > 2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png"); > CRect rect; > GetClientRect(&rect); > > CWindowDC pDC(this); > CDC dc; > OK=m_Image.Load(lpBitSource); > dc.CreateCompatibleDC(&pDC); > > m_Image.Draw(pDC.m_hDC,CRect(&rect)); > > Thanks for answers. > > Manu > > > >
From: Joseph M. Newcomer on 20 Feb 2010 01:24 See below... On Tue, 16 Feb 2010 18:33:49 +0100, "Manuel Hoeger" <Manuel.Hoeger(a)physik.stud.uni-erlangen.de> wrote: >Hi, > >I tried to show a png Image using CImage ( Visual Studio 2008 prof ) > >It works pretty good, but only in Release Mode. If I run it in Debug Mode >there is a Message: > >"Debug Assertion Failed! >Program: ....[..]\application.exe >File: g:[...]\atlimage.h >Line: 503 > >Expression: m_hbitmap == 0 >[..] **** It is pretty clear what this means. It means that the m_hBitmap member of the class MUST be NULL, and it ISN'T NULL. Why not? Because you already have an image attached to it! Nowhere did I see where m_Image is freeing the image. Which leads to the question of why, in your OnDraw/OnPaint handler, you are storing the image which you are just loading into a class member, instead of a local variable. **** > > >if I ignore the message the picture is schown. How can I avoid this Failure > >My Code: > >BOOL OK; > LPCTSTR lpBitSource=_T("D:\\Daten\\Visual Studio >2008\\Projects\\LitLaunchTestbox\\LitLaunch\\brett1.png"); **** I presume the goal here is that this program will run correctly only today, on your machine, and you never expect it to run anywhere else. Otherwise, hardwiring a path like this in represents a serious problem. **** > CRect rect; > GetClientRect(&rect); > > CWindowDC pDC(this); **** Do you really want a window DC? Why? Wouldn't CClientDC dc(this) be more appropriate? **** > CDC dc; > OK=m_Image.Load(lpBitSource); **** Once it is loaded, it is loaded forever, and any attempt to load it again generates the error you see. You must explicitly delete this image with CImage::Destroy, e.g., after you draw it, you must do m_Image.Destroy(); but why does m_Image exist at all? A local variable would be perfect for this! **** > dc.CreateCompatibleDC(&pDC); > > m_Image.Draw(pDC.m_hDC,CRect(&rect)); **** I am presuming this is in your OnDraw/OnPaint handler. If it isn't, all of the above code is incorrect. It would be correct only if it were in the OnDraw/OnPaint handler. joe **** > >Thanks for answers. > >Manu > > > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Pages: 1 Prev: Changing default of static control Next: dtor not called |