是的,没有delete。
如果是成员变量,可以放在析构函数中delete。
如果是局部变量,那么在那个窗口的OnNCDestroy(窗口销毁的最后一个消息)中调用delete this

解决方案 »

  1.   

    CMulMode *pMtm=new CMulMode;
    要全局的
    CMulMode *m_pMtm;
    到 不要时 delete m_pMtm;
      

  2.   

    嗯嗯,大致明白了。
    void CDestroyWindowDlg::OnOK() 
    {
    // TODO: Add extra validation here

    CDialog::OnOK();
    }void CDestroyWindowDlg::PostNcDestroy() 
    {
    // TODO: Add your specialized code here and/or call the base class

    // CDialog::PostNcDestroy();
    }void CDestroyWindowDlg::OnDestroy() 
    {
    //CDialog::OnDestroy();
    // TODO: Add your message handler code here

    }void CDestroyWindowDlg::OnCancel() 
    {
    // TODO: Add extra cleanup here

    CDialog::OnCancel();
    }其实我这里完全可以用模态的,就是想尝试用一下非模态的。
    我按二楼说的,断点查了下,大致顺序是:OnOK或者OnCancel---OnDestroy---PostNcDestroy而且在一旦进入到OnDestroy窗口就没有了,刚开始,我以为是因为OnDestroy调用了CDialog::OnDestroy();,因为OnDestroy函数里面只有一句代码,就是CDialog::OnDestroy();。但是我尝试把这句代码注释掉,我以为窗口应该不会消失,可是还是小事了;另外,我把PostNcDestroy函数代码注释掉,窗口一样会销毁。这就很奇怪了。不过好歹弄清楚了他们的先后顺序,我决定把delete this放在PostNcDestroy里面了。
      

  3.   

    “这就很奇怪了”
    没什么奇怪的, windows 有 一类 消息, 只是 告诉 你 发生了 什么, 没有要你 做什么。系统自己做。
      

  4.   

    刚查了下CSDN,关于OnNcDestroy的说明如下:
    afx_msg void OnNcDestroy( );ResCalled by the framework when the nonclient area is being destroyed, and is the last member function called when the Windows window is destroyed. The default implementation performs some cleanup, then calls the virtual member function PostNcDestroy. Override PostNcDestroy if you want to perform your own cleanup, such as a delete this operation. If you override OnNcDestroy, you must call OnNcDestroy in your base class to ensure that any memory internally allocated for the window is freed.大致意思感觉是:OnNcDestroy() 是非客户区被销毁的时候调用的,窗口销毁调用的最后一个函数;用来做一些清理工作,然后调用虚函数PostNcDestroy。如果需要的话最好是重载PostNcDestroy(这里还真提到了用于delete this),但是貌似不建议重载OnNcDestroy.
     最后一句没明白...
    如果我重载了OnNcDestroy了,我必须调用我的基类的OnNcDestroy以确保非陪给窗口的所有内存都被释放了
    举个例子,如果我在一个对话框上有个按钮,会弹出一个子对话框,子对话框是继承CDialog的,这个时候,我根本在子对话框上都找不到OnNcDestroy这个函数,怎么重载,只能找到PostNcDestroy这个;就算找到了,我重载了,我难道要调用CDialog::OnNcDestroy()?
      

  5.   

    PostNcDestroy  就是 “Post   NcDestroy” 即 NcDestroy