Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems with CBitmap

Started by raklar Mar 15, 2003 at 9:52 PM 2 replies 550+ views
Original Post
raklar
raklar
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(); }
Richard S. Bezemer
felisandria
felisandria
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

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
raklar
raklar
Yes, I''m calling a Destroy window befor I delete the dialog pointer.
Richard S. Bezemer
raklar
raklar
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....
Richard S. Bezemer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.