【问题标题】:How to close a MFC CVIEW while keeping the document open如何在保持文档打开的同时关闭 MFC CVIEW
【发布时间】:2012-11-09 10:03:52
【问题描述】:

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

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

我想我可以将它与 CDocument::RemoveView 结合使用。有没有比仅仅提升 MFC 源更好的方法来解决这个问题,这种方法会不会给我带来其他问题或副作用?项目为VS2010 C++。

【问题讨论】:

    标签: c++ visual-studio-2010 mfc document-view


    【解决方案1】:

    如果您将 CDocument::m_bAutoDelete 设置为 FALSE(在创建文档之后),它不应该在最后一个视图关闭时删除文档。

    我不确定您具体要做什么,但您可能需要考虑创建一个单独的“数据”对象,该对象可以附加到文档中,而不是试图保留文档本身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多