-
Dynamic Views
I have a SDI project where the Mainframe contains a splitter window with two
panes. Inside CMainFrm I have a function that will change the views in the
right pane dynamically. All of this works fine, except when I go to
serialize a view via the document. When I do this, the following call is
made to delete the view inside CMainFrm.
m_Splitter.DeleteView(0, 1);
It does not crash but it hangs on the ::DestroyWindow(hwnd) function inside
CWnd::DestroyWindow(). Like I said before, if I do not serialize everything
works fine. I thought at first it might be some internal CDocument thing,
so I moved the Serialize job to CMainFrm and just used CDocument to check to
see if the view has been modified or not. But the same thing happens.
This is how it works, I click on something in the left pane, which sends a
message
to my CMainFrame class, which in turn decides whether it needs to change the
view.
If it decides to change the view it calls the following function.
ChangeViews(RUNTIME_CLASS(CSomeView));
I have followed it all the way into the CWnd::DestroyWindow() call and
everything looks ok.
But when it calls ::DestroyWindow(m_hwnd), it hangs.
Here is the function that I use to switch views:
bool CMainFrame::ChangeViews(CRuntimeClass * pViewClass)
{
// Set no active view since we are destroying the only view
SetActiveView(NULL, FALSE);
CView * pView = (CView*) m_Splitter.GetPane(0, 1);
ASSERT_VALID(pView);
CEstimatorDoc * pDoc = (CEstimatorDoc *) pView->GetDocument();
ASSERT_VALID(pDoc);
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;
m_Splitter.DeleteView(0, 1); // this is where it hangs when it calls ::DestroyWindow()
CCreateContext context;
context.m_pCurrentDoc = pDoc;
context.m_pNewDocTemplate = pDoc->GetDocTemplate();
context.m_pNewViewClass = pViewClass;
context.m_pLastView = pView;
context.m_pCurrentFrame = this;
m_Splitter.CreateView(0, 1, pViewClass, CSize(0,0), &context);
m_Splitter.RecalcLayout();
pDoc->m_bAutoDelete = bSaveAutoDelete;
pDoc->SetModifiedFlag(FALSE);
pView = (CView*) m_Splitter.GetPane(0, 1);
ASSERT_VALID(pView);
pView->SendMessage(WM_INITIALUPDATE);
SetActiveView(pView);
m_pCurrentView = pView;
// Update all views
pDoc->UpdateAllViews(NULL);
return true;
}
Any help would be appreciated,,
Wayne