本帖最后由 wenhongshen 于 2012-10-22 14:00:48 编辑

解决方案 »

  1.   

    放Frame的OnCose、OnDestory或者CYourWinApp::ExitInstance中都可以吧。
      

  2.   


    谢谢您的帮助,我加入如下代码,没效果,还是一样出错,不知道哪里出了问题?请大家指教!void CSwhMdiMisFrame::OnClose() 
    {
    // TODO: Add your message handler code here and/or call default
       CMainFrame* crd=(CMainFrame*)GetParent();
       crd->m_pFuncFrame=NULL;
       delete crd->m_pFuncFrame;
    CMDIChildWnd::OnClose();
    }
      

  3.   

    if(m_pFuncFrame)
    {
     delete m_pFuncFrame;
    m_pFuncFrame=0;
    }
    m_pFuncFrame = new CSwhMdiMisFrame();  
      

  4.   

    if(m_pFuncFrame)
    {
    delete m_pFuncFrame;
    m_pFuncFrame = 0;
    }
    m_pFuncFrame = new CSwhMdiMisFrame(); 
      

  5.   

    楼主意思是如果该指针存在那么就不新建了。应该在销毁和析构的时候处理好,楼主在析构的时候肯定只delete,delete只是释放了相关内存
    没有把指针置空掉。你应该析构的地方delete再置空指针
      

  6.   

    //
    if(m_pFuncFrame)
    {
    delete m_pFuncFrame;
    m_pFuncFrame = 0;
    }
    // 是防止多次 new
    m_pFuncFrame = new CSwhMdiMisFrame(); 
    //
    最后析构的地方还要 delete
      

  7.   

    CSwhMdiMisFrame* m_pFuncFrame;
    -----------------------------
    CSwhMdiMisFrame的基类是什么?CFrameWnd吗?
      

  8.   

    我觉得应该先delete后置NULL:
    void CSwhMdiMisFrame::OnClose() 
    {
    // TODO: Add your message handler code here and/or call default
      CMainFrame* crd=(CMainFrame*)GetParent();
      delete crd->m_pFuncFrame;//顺序反一下
      crd->m_pFuncFrame=NULL;
    CMDIChildWnd::OnClose();
    }
      

  9.   

    IMPLEMENT_DYNCREATE(CSwhMdiMisFrame, CMDIChildWnd)
    基类是CMDIChildWnd
      

  10.   


    我看了您的代码,这是可以的,不管childframe有没有打开我都重建,但是违背了我的初衷:
    如果这个childframe 已经打开了,我就直接激活,不要重建,如果没打开在重建
    if (m_pFuncFrame != NULL)  
    {  
    m_pFuncFrame->MDIActivate(); 
    return ;  
    }  
    m_pFuncFrame = new CSwhMdiMisFrame();  
      

  11.   

    放在CSwhMdiMisFrame的OnCreate里面。
    m_pFuncFrame初始化为NULL。m_pFuncFrame = NULL;
    如果有地方析构的话,那么delete m_pFuncFrame之后,不要忘记m_pFuncFrame = NULL;
      

  12.   

    非常感谢您的指点,不过估计您没仔细,m_pFuncFrame 是在 CMainFrame中定义的。我对vc还知之皮毛// MainFrm.h : interface of the CMainFrame classpublic:CMultiDocTemplate* pDocTemplate;CSwhMdiMisFrame* m_pFuncFrame;--------------// MainFrm.cpp : implementation of the CMainFrame classCMainFrame::CMainFrame(){// TODO: add member initialization code here
    m_pFuncFrame = NULL; 
    }----------------------------
    // SwhMdiMisFrame.cpp : implementation file#include "MainFrm.h"CSwhMdiMisFrame::~CSwhMdiMisFrame(){
    CMainFrame* crd=(CMainFrame*)GetParent();//关闭时,运行到这里出错了提示: file:afxwin2.inl line 265delete crd->m_pFuncFrame;//crd->m_pFuncFrame=NULL; 
    }
    不知道是哪里出了问题,请指教!谢谢先
      

  13.   

    直接在CMainFrame的析构里面if(m_pFuncFrame)
    {
    delete m_pFuncFrame;
    m_pFuncFrame = NULL;
    }
      

  14.   

    “我想知道当我点击关闭时,该在哪里释放这个指针:m_pFuncoFrame”如果只是关闭子窗口,不关闭整个程序,这个指针是不需要释放的
    “运行后有frame出来,当关闭有再次打开时运行到这里 m_pFuncFrame->MDIActivate(); 出错”可能是MDIActivate()函数的代码有问题
      

  15.   

    非常感谢大家的帮助,问题解决了:
    void CFuncView::OnDestroy() 
    {
    CFormView::OnDestroy();

    // TODO: Add your message handler code here
    ((CMainFrame*)AfxGetMainWnd())->m_pFuncFrame=NULL;
    }