Click here to Skip to main content
12,759,704 members (33,160 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC GUI

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.

//here I get the document of the old view I'm going to delete
Context.m_pNewDocTemplate= Context.m_pCurrentDoc->GetDocTemplate();
//here I delete the old view
//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);

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
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.
Rate this: bad
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.

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 22 Feb 2012
Copyright © CodeProject, 1999-2017
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