我的程序在启动时出现登录对话框,如果点击了"取消",需要退出程序,我用
PostQuitMessage(0);退出,结果OnDestroy() 执行不到,各位谁知道怎么解决?
void CManagerView::OnShowWindow(BOOL bShow, UINT nStatus) 
{
 .........
PostQuitMessage(0);
}
void CManagerView::OnDestroy() 
{
CListView::OnDestroy();
if(m_pDB!=NULL)
{
delete m_pDB;
}
if(m_pSnmp!=NULL)
{
delete m_pSnmp;
}
}

解决方案 »

  1.   

    用DestroyWindow函数试试。他的默认动作是发送WM_DESTROY和WM_NCDESTROY消息。WM_DESTROY 将引起OnDestroy操作。
      

  2.   

    PostQuitMessage直接使消息循环退出了,窗口消息处理的OnDestroy得不到执行。
      

  3.   

    PostQuitMessage(0);前自己调用一次OnDestroy(),
    当然,你得先得到View的指针,
    同时,把OnDestroy声明成Public
      

  4.   

    这是显示:
    Warning: destroying CSingleDocTemplate with live document.
     在语句
    IMPLEMENT_DYNCREATE(CManagerView, CListView)处提示:
    J:\snmp\Manager\ManagerView.cpp(28) : {101} client block at 0x003C5B10, subtype 0, 872 bytes long.
    a CManagerView object at $003C5B10, 872 bytes long
    我问一下,在程序已经初始话完成的时候怎么正常退出,而不会泄漏内存?
      

  5.   

    OnDestroy(),DestroyWindow 好像都是顾此失彼,没有走正常退出的流程,或者我的函数放的不是位置,泄漏依旧...
      

  6.   

    用 OnNcDestroy()。void CManagerView::OnNcDestroy()
    {
        CListView::OnNcDestroy();    PostQuitMessage(0);
    }
      

  7.   

    请看看msdn上的如下解释:The PostQuitMessage function posts a WM_QUIT message to the thread's message queue and returns immediately; the function simply indicates to the system that the thread is requesting to quit at some time in the future. Use the PostQuitMessage function to exit a message loop. PostQuitMessage posts the WM_QUIT message to the currently executing thread. The thread's message loop terminates and returns control to the system when it encounters the WM_QUIT message. An application usually calls PostQuitMessage in response to the WM_DESTROY message, as shown in the following example. case WM_DESTROY: 
     
        // Perform cleanup tasks. 
        PostQuitMessage(0); 
        break; The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
     
    CWnd::OnDestroy --The framework calls this member function to inform the CWnd object that it is being destroyed.因此,如 enoloo(努力COM) 所说的,“PostQuitMessage直接使消息循环退出了,窗口消息处理的OnDestroy得不到执行。”