-
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
-
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.
-
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
-
thanks everyone
resources are being freed as they should be
awni