删除视图但避免文档被破坏,保留文档 [英] Delete a view but avoid document destruction, preserve document

查看:72
本文介绍了删除视图但避免文档被破坏,保留文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有这个问题.

我在拆分器的窗格中有一个视图,并且在窗格内切换了视图.我做这样的事情.

Hello,

I have this issue.

I have a view in a pane of a splitter and I switch the view inside the pane. I do something like that.

Context.m_pNewViewClass=RUNTIME_CLASS(CConfigViewPlugin);
Context.m_pCurrentDoc=pView->GetDocument();
Context.m_pCurrentFrame=this;
//here I get the document of the old view I'm going to delete
Context.m_pNewDocTemplate= Context.m_pCurrentDoc->GetDocTemplate();
Context.m_pLastView=(CView*)m_wndSplitter.GetPane(0,1);
//here I delete the old view
m_wndSplitter.DeleteView(0,1);
//I create the new view CRASH!! BECAUSE THE DOCUMENT IS NOT VALID ANYMORE, the document has been deleted from mfc together with the old view
m_wndSplitter.CreateView(0, 1,RUNTIME_CLASS(CConfigViewPlugin),paneSize1, &Context);
pView=(CConfigViewRec*)m_wndSplitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_wndSplitter.RecalcLayout();




现在,我的问题是,当我删除旧视图时,mfc销毁了文档,我试图将NULL文档和NULL doctemplate传递给新视图,但是我想保留文档并将其传递给新视图,




Now, my problem is, when I delete the old view, mfc destroy the document, i tryed to pass to the new view a NULL document and NULL doctemplate, but I would like to preserve the document and pass it to the new view,, How can I do?

推荐答案

关闭MDI文档的最后一个视图时,该文档将被销毁.为避免这种情况,请在关闭旧视图之前创建一个新视图.
When closing the last view of a MDI document, the document is destroyed. To avoid this, create the new view before closing the old one.


可能您的建议有效,但是我发现了两种解决方案:

1-在文档中,将bool m_bAutodelete更改为False,并在完成替换后将其重新设置为True.

2-我在拆分器中发现了一个漂亮的replaceview方法,它会自动为我做所有事情.我实现了这一点. http://support.microsoft.com/kb/149257
Probably your suggestion works, however I found 2 solutions:

1- In the document change the bool m_bAutodelete to False, and set back to True once I finish to replace.

2- I found a beautiful replaceview method in the splitter, It do everything for me automatically. I implemented this one. http://support.microsoft.com/kb/149257

PS: I tested the 1st solution as well, just to try.. and it also works.

PS2: I realized ReplaceView CPlitter method is not a native method of MFC CSplitter, I''m using a derivated CSplitter of CodeJock library and it offer this method.


这篇关于删除视图但避免文档被破坏,保留文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆