Article ID: 196832
Article Last Modified on 11/21/2006
CMyDoc::CMyDoc()
{
m_bAutoDelete = FALSE;
}
CMainFrame::OnClose()
{
GetActiveDocument()->m_bAutoDelete = TRUE;
CFrameWnd::OnClose();
}
class CMainFrame : public CFrameWnd
{
...
protected:
CSplitterWnd *m_pSplitter;
...
};
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here.
m_pSplitter = NULL;
}
CMainFrame::~CMainFrame()
{
if (m_pSplitter)
delete m_pSplitter;
}
#include "MyDoc.h"
#include "MyView.h"
#include "Pane1View.h"
#include "Pane2View.h"
void CMainFrame::OnUpdateViewSplitterWnd(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here.
pCmdUI->SetCheck(m_pSplitter!=NULL);
}
void CMainFrame::OnViewSplitterWnd()
{
// TODO: Add your command handler code here.
CCreateContext ctx;
ctx.m_pNewViewClass = RUNTIME_CLASS(CMyView);
// GetActiveDocument() call before you destroy m_splitter.
ctx.m_pCurrentDoc = GetActiveDocument();
ASSERT(ctx.m_pCurrentDoc!=NULL);
// m_pSplitter !=NULL when there is a visible splitter.
if (m_pSplitter)
{
// Destroy splitter window.
delete m_pSplitter;
m_pSplitter = NULL;
// Create and initialize CMyView.
SetActiveView((CView*)CreateView(&ctx));
GetActiveView()->OnInitialUpdate();
}
else
{
// Destroy CMyView.
GetActiveView()->DestroyWindow();
// Create new splitter window.
m_pSplitter = new CSplitterWnd;
if (!m_pSplitter->CreateStatic(this, 1, 2))
{
TRACE0("Can't create splitter window.\n");
return;
}
else
{
if ((!m_pSplitter->CreateView(0, 0,
RUNTIME_CLASS(CPane1View),
CSize(200, 0), &ctx))
||(!m_pSplitter->CreateView(0, 1,
RUNTIME_CLASS(CPane2View),
CSize(500, 0), &ctx)))
{
TRACE0("Can't create one of the splitter panes.\n");
return;
}
// Initialize the two panes (each containing a view
// associated with the current document).
((CView*)m_pSplitter->GetPane(0, 0))->OnInitialUpdate();
((CView*)m_pSplitter->GetPane(0, 1))->OnInitialUpdate();
SetActiveView((CView*)m_pSplitter->GetPane(0, 0));
}
}
// Redisplay frame.
RecalcLayout();
}Keywords: kbdocview kbhowto kbuidesign KB196832