|
-
October 3rd, 2003, 09:04 AM
#1
freeing gdi resources
Hi
I have global variables :
CDC g_dc;
CBitmap g_bmp;
both of these are deleted and recreated in OnSize
Code:
...
g_bmp.DeleteObject();
g_dc.DeleteDC();
g_dc.CreateCompatibleDC(&ScreenDC);
g_bmp.CreateCompatibleDC(&g_dc, newWidth, newHeight);
...
the resources don't seem to be freed correctly, because after
resizing the window a few times, the application cannot create a bitmap anymore using CreateCompatibleBitmap(..)
what can i do to fully free the resources?
thanks
awni
-
October 3rd, 2003, 09:38 AM
#2
This would not be my prefered approach; I'd tend to put the bitmap creation in the paint handler and either create the global dc once, or as needed in the paint (The compatible DC does not need to be recreated on size or bitmap changes). Other than that, you need to ensure that the bitmap is not selected into the DC when you delete it.
bytz
--This signature left intentionally blank--
-
October 3rd, 2003, 10:46 AM
#3
Hi Awni,
Before you DeleteObject(), you need to select the old bitmap back into DC...maybe thats what eating up resources...
Code:
CBitmpap* pOldBitmap=g_dc.SelectObject(&g_bmp);
//use it then
g_dc.SelectObject(pOldBitmap);// selecting back the original bitmap
g_bmp.DeleteObject();
//etc
Hope that helps
Regards
Mustafa
______________________________
To err is human, it's the computer that causes blunders !!!
DO: Dazzle me with your intelligence
DON'T : Confuse me with your bullshit
-
October 8th, 2003, 11:43 AM
#4
thanks everyone
resources are being freed as they should be
awni
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|