Archived

This topic is now archived and is closed to further replies.

raklar

Problems with CBitmap

Recommended Posts

raklar    122
Hello, I''m trying to load a CBitmap from a file using a HBitmap and attach() , but my program keeps on crashing whenever I delete the pointer to the dialog box to close it(doing a modless dialog box toolbar thingy). I''m guessing I have a memory leak somewhere but it''s getting very frustrating. The only time it seems to not crash on exit is when the attach() method is not called (of course then I can''t see my bitmap).any comments would be greatly appreciated. thanks. void CTileSelector::OnPaint() { CPaintDC dc(this); // device context for painting CBitmap ImageList; /*hImage is a global HBITMAP which has been previously loaded with a bitmap file.*/ ImageList.Attach(hImage) SIZE ImageSize; BITMAP bmp; ImageList.GetObject(sizeof(BITMAP),&bmp) CDC dcMem; dcMem.CreateCompatibleDC(NULL); dcMem.SelectObject(&ImageList); ImageSize.cx=bmp.bmWidth; ImageSize.cy=bmp.bmHeight; dc.BitBlt(xc,10,32,32,&dcMem,ix,iy,SRCCOPY); dcMem.DeleteDC(); ImageList.Detach(); ImageList.DeleteObject(); }

Share this post


Link to post
Share on other sites
felisandria    739
Are you sure you''re closing your dialog correctly? You shouldn''t just delete the thing without asking it nicely to close. Try using a WM_CLOSE.

Often problems that look like paint problems are actually due to improper dialog shutdowns, it''s just that the paint makes it so that the OnPaint is being handled longer than it would with an empty dialog, which causes fits to be thrown.

-fel

Share this post


Link to post
Share on other sites
raklar    122
found it!!! was a multitude of problems but finally I think I found the problem. I''ve rewritten the code so many time in the last few days I''m not even sure exatcly what I did to fix it....

Share this post


Link to post
Share on other sites