From the WTL newsgroup (sign up! -- http://groups.yahoo.com/group/wtl) From: "Tim Smith" Date: Thu Jan 18, 2001 11:41 am Subject: Re: DestroyWindow and OnFinalMessage ? Here is a basic roadmap of what you need to do. First, inside your dialog box class, you need make a new version of DialogProc. I just copied the DialogProc from ATL. Next, add a flag to your class called m_fDeferDelete. Initialize it to false. Inside your new DialogProc, in the WM_NCDESTROY clause after the call to OnFinalMessage, add the following lines: if (pThis ->m_pCurrentMsg == NULL) delete pThis; else pThis ->m_fDeferDelete = true Then in your new DialogProc, after the call to ProcessWindowMessage, add the code: if (pThis ->m_fDeferDelete && pOldMsg == NULL) { delete pThis; return FALSE; } There might be a better way to do it, but this will work. In my real code, I created a new base class that included an auto delete flag. All my dialogs are based on this class. If the auto delete flag is not set, then the dialog works normally. If it is set, then the class self deletes as expected.