PostQuitMessage() = Bad Things. Gotcha. ;-)
You and David were right about my destructor and OnDestroy(). Thank
you.
Wonderful website, by the way.
Joseph M. Newcomer wrote:
This is the worst possible way to accomplish this, and it will eventually result in
serious problems including data loss. NEVER call PostQuitMessage like this; it shuts down
the message pump IMMEDIATELY, thus making it impossible for the program to ask questions
like "Your document has changed, do you want to save these changes? [Yes, No, Cancel]".
There is no reason to destroy the menu unless it is a menu you have created, in which case
you would handle this task in the OnDestroy handler, not in the OnExit handler; for a
popup menu, you would destroy the menu the same way it is handled for any other popup,
usually by having a CMenu variable leave scope. What you need to do is
PostMessage(WM_CLOSE);
to the mainframe.
Note that destructors are called NOT when windows are destroyed, but when the variable
that represents them goes out of scope or (for heap-allocated objects) when delete is
called. I suspect you are trying to do things in a destructor that should more properly
be done in the OnDestroy handler. Since you don't explain what these are, it is hard to
guess, but it is entirely possible your destructor isn't called until very late in the
process of shutdown, or possibly never.
joe
On 4 Aug 2006 15:18:27 -0700, "PaulH" <paul.heil@gmail.com> wrote:
I have an MFC app that runs in the taskbar. When the user wants to
quit, I have an "exit" item in a pop-up menu (m_hMenu) as below:
void CMyWnd::OnMenuExit()
{
Shell_NotifyIcon(NIM_DELETE, &m_nid);
::DestroyMenu(m_hMenu);
PostQuitMessage(0);
}
But, I have some cleanup code in my destructor ~CMyWnd() that never
gets called. Why not?
I've also tried using PostMessage(WM_CLOSE) instead of
PostQuitMessage(0) with no difference.
Thanks,
PaulH
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm