Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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();



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?
Posted

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.
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900