C++ 如何在保持文档打开的同时关闭MFC视图

C++ 如何在保持文档打开的同时关闭MFC视图,c++,visual-studio-2010,mfc,document-view,C++,Visual Studio 2010,Mfc,Document View,我在MDI应用程序中打开了MFC CDocument和相关CView。我想分离并关闭视图(和关联的框架),同时保持文档打开。查看MFC代码以了解它是如何工作的,在CDocument::OnCloseDocument()中显示了以下内容: 我想我可以将其与CDocument::RemoveView结合使用。除了提升MFC源之外,还有更好的方法吗?这种方法会给我带来其他问题或副作用吗?项目是VS2010 C++。< P>如果将CDOff::MyButoDeleDebug设置为false(创建文档之后

我在MDI应用程序中打开了MFC CDocument和相关CView。我想分离并关闭视图(和关联的框架),同时保持文档打开。查看MFC代码以了解它是如何工作的,在CDocument::OnCloseDocument()中显示了以下内容:


我想我可以将其与CDocument::RemoveView结合使用。除了提升MFC源之外,还有更好的方法吗?这种方法会给我带来其他问题或副作用吗?项目是VS2010 C++。

< P>如果将CDOff::MyButoDeleDebug设置为false(创建文档之后),在最后一个视图关闭时不应该删除文档。

我不确定你具体想做什么,但是你可能想考虑创建一个单独的“数据”对象,它可以附加到一个文档上,而不是试图保持文档本身。

// 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();

    // and close it
    PreCloseFrame(pFrame);
    pFrame->DestroyWindow();
        // will destroy the view as well
}
m_bAutoDelete = bAutoDelete;