Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC GUI
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();
 

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 21-Feb-12 22:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 420
1 OriginalGriff 230
2 DamithSL 175
3 Dave Kreskowiak 120
4 Zoltán Zörgő 114
0 OriginalGriff 7,740
1 DamithSL 5,644
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,011
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 22 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100