InitialUpdateFrame的用法
在删除视图的情况下在分割器窗口中进行视图的切换
void CMainFrame::SwitchViewInSplitter(int row, int col, CRuntimeClass *pViewClass)
{
//(1)查找要替换的视图
CWnd* pPaneWnd = m_wndSplitter.GetPane(row,col);
if (!pPaneWnd->IsKindOf(RUNTIME_CLASS(CView)))
{
return;
}
CView* pCurrentView = static_cast<CView*>(pPaneWnd);
//(2)保存当前视图的位置和活动状态
CRect rcView;
pCurrentView->GetWindowRect(&rcView);
CView* pActiveView = m_wndSplitter.GetParentFrame()->GetActiveView();
BOOL bSaveActive = (pActiveView == NULL || pActiveView == pCurrentView);
//(3)查找相关的文档
CDocument* pDoc = pCurrentView->GetDocument();
//(4)当释放位图时,确保不会释放文档
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;
//(5)释放活动视图
pCurrentView->DestroyWindow();
//(6)恢复文档到初始状态
pDoc->m_bAutoDelete = bSaveAutoDelete;
//(7)初始化CreateView使用地上下文
CCreateContext context;
context.m_pCurrentDoc = pDoc;
context.m_pNewViewClass = pViewClass;
context.m_pCurrentFrame = NULL;
context.m_pLastView = NULL;
context.m_pNewDocTemplate = NULL;
//(8)创建新视图
m_wndSplitter.CreateView(row,col,pViewClass,rcView.Size(),&context);
//(9)定位视图与激活
CView* pNewView = (CView*)m_wndSplitter.GetPane(row,col);
m_wndSplitter.ScreenToClient(&rcView);
pNewView->MoveWindow(&rcView);
if (bSaveActive)
{
m_wndSplitter.GetParentFrame()->SetActiveView(pNewView);
}
//(10)给视图发送WM_INITIALUPDATE消息
pNewView->GetParentFrame()->InitialUpdateFrame(pDoc,TRUE);
}
这是一个转换视图的函数,我在用它的时候到最后一句pNewView->GetParentFrame()->InitialUpdateFrame(pDoc,TRUE);的时候总是出现断言错误,为什么会这样呢?
我自己写了一个转换视图的函数,也是运行到pNewView->GetParentFrame()->InitialUpdateFrame(pDoc,TRUE);的时候出错,我怀疑是我的document文件有问题,到底是怎么回事儿?
MSDN写的不清不楚的,不是说MSDN不好,是我自己弱,希望解答