Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Update Messages during window destruction Collapse All
Subject Author Date
John Ritzenthaler Feb 27, 2009 - 5:32 PM

I have modeless CExtResizableDialog windows that I destroy simply by deleteing the dialog object.  This worked fine with CDialog.


But with CExtResizableDialog, I sometimes get ON_UPDATE_COMMAND_UI messages during the destruction.  This causes all kinds of problems with parts of the member data freed.


Is there some was to turn these off before I destroy the window or some recommended sequence for destorying the dialog?

Technical Support Mar 1, 2009 - 4:47 AM

You should not destroy any CWnd-based C++ objects using the delete operator while these objects still subclass HWND window handle. You should not do this even if there are no crashes and assertions occur for particular CWnd-derived classes. At least, MFC prints warning messages into the Output window in Visual Studio when such objects are deleted. Such deletion is not suggested by MFC. Please invoke the CWnd::DestroyWindow() virtual method for destroying any kind of windows. Please override the CWnd::PostNcDestroy() virtual method and invoke the delete this; line of code at the end of it if your window should delete itself automatically. The CWnd::PostNcDestroy() virtual method is invoked when window handle is destroyed and when it was not created successfully inside invocation of the Create***() methods of any MFC and Prof-UIS classes. So, if you have the instance of some CWnd-based class which is allocated dynamically with the C++ new operator and if it’s Create() method returned negative result, then the PostNcDestroy() virtual method still allows you to self delete this object.

John Ritzenthaler Mar 4, 2009 - 9:44 AM

Thanks for the education.  Sorry to have bothered you with something I thought was ProfUIS related.