I have used CreateStatic & CreateView to split “C(classname)View” into many panes (like (1×2), (3×3)) using button control to choose the number of rows and columns.
Now, when I click 1×1 (which means I want to remove any panes), ASSERT(n_Row > 1 && n_Col > 1) obviously fails inside CSplitterWnd::CreateStatic.
How do I handle the “no-panes” situation?
This is the DisplaySingleFrame() Function (which removes the panes)
CN00bSplitApp* pApp = (CN00bSplitApp*)AfxGetApp();
CView * pActiveView = NULL;
if(pActiveView == NULL)
{
if(m_pSplitter)
pActiveView = (CView*)m_pSplitter->GetPane(0,0);
else
pActiveView = (CN00bSplitView *)GetActiveView();
}
m_iPrevColLayout = m_iRowLayout;
m_iPrevRowLayout = m_iColLayout;
m_iRowLayout = 0;
m_iColLayout = 0;
ShowWindow(SW_HIDE);
CRect rect(0,0,0,0);
pActiveView->GetClientRect(rect);
CDocument * pDoc= pActiveView->GetDocument();
pActiveView->DestroyWindow();
pActiveView = NULL;
if(m_pSplitter)
{
m_pSplitter->DestroyWindow();
delete m_pSplitter;
m_pSplitter = NULL;
}
CDocTemplate* pDocTemplate = pApp->m_pDocTemplate;
CCreateContext context;
context.m_pNewViewClass= RUNTIME_CLASS(CN00bSplitView);
context.m_pCurrentDoc=(CN00bSplitDoc*)pDocTemplate->CreateNewDocument();
context.m_pLastView=pActiveView;
CView* p = (CView*)CreateView(&context, AFX_IDW_PANE_FIRST);
SetActiveView(p);
p->OnInitialUpdate();
RecalcLayout();
ShowWindow(SW_SHOW);
This throws an unhandled exception at “context.m_pCurrentDoc=(CN00bSplitDoc*)pDocTemplate->CreateNewDocument();”
I hadn’t initialized
m_pDocTemplate=pDocTemplatein the InitInstance of theC(classname)App.Solves the problem.