我的MFC关闭时,连续调用两次while (!m_viewList.IsEmpty()),从而导致第二次调用的时候主框架窗口销毁了,不知道是什么原因,哪位遇到过?

解决方案 »

  1.   

    void CDocument::OnCloseDocument()
    // must close all views now (no prompting) - usually destroys this
    {
    // destroy all frames viewing this document
    // the last destroy may destroy us
    BOOL bAutoDelete = m_bAutoDelete;
    m_bAutoDelete = FALSE;  // don't destroy document while closing views
    while (!m_viewList.IsEmpty())
    {
    // get frame attached to the view
    CView* pView = (CView*)m_viewList.GetHead();
    ASSERT_VALID(pView);
    CFrameWnd* pFrame = pView->EnsureParentFrame();
    就是这个函数里面的这个语句调用两次,我的是单文档程序,怎么会调用两次呢?从而就导致我的程序退出时出错
      

  2.   

    就是while循环调用两次  好奇怪,我的是单文档程序
      

  3.   

    自己重载这个
    OnCloseDocument
    在里面用if判断,防止崩溃