Reputation: 17313
I program using C++/MFC in a native WinAPI world. Say, I have a dialog window class (creatred in MFC and derived from CDialog.) I also created a timer, using SetTimer method when the window was about to be displayed, in OnInitDialog(). My issue is when do I need to properly release this timer (or other allocated resources)?
PS. I tried doing it in PostNcDestroy() but KillTimer fails. But when I do it in OnClose/WM_CLOSE it works, but not when a user clicks OK button to close the dialog. Is there a uniform notification to do it in?
Upvotes: 1
Views: 711
Reputation: 13083
I'm doing it in the ON_WM_DESTROY handler. Which is called between WM_CLOSE and PostNcDestroy method. This is the place where you should destroy all window resources.
And remember that for example GDI resources should freed as fast as possible, recreating does not really cost time anymore and the number of GDI resources is extremely low. I think it is by default something like 10000 for the whole system, even under 64bit Windows.
Upvotes: 3