下面是在静态拆分窗口中切换不同View的方法
可是这句
CRuntimeClass *pViewClass=RUNTIME_CLASS(CFormDataView);
用CListView或者其它View类派生的类运行起来都没有问题
但是我希望的CFormView类却总是运行错误~
注:我建立CFormView的方法是插入一个dialog资源,设计好了以后用wizzard插入一个CFormView类
这样是不是不对啊?
//为了实现,函数中已经把类型设定好了~
BOOL CMainFrame::SetActivePage()
{
CRuntimeClass *pViewClass=RUNTIME_CLASS(CFormDataView);
int row=0;
int col=1;
CSize size(100, 100);
CCreateContext context;
BOOL bSetActive;
if ((this->m_wndSplitter.GetPane(row, col)->IsKindOf(pViewClass)) == TRUE)
return FALSE;
//获取文档对象的指针,以便在创建新视图的过程中能够使用它
CDocument *pDoc = ((CView*)m_wndSplitter.GetPane(row, col))->GetDocument();
CView *pActiveView = this->GetActiveView();
if (pActiveView == NULL || pActiveView == m_wndSplitter.GetPane(row, col))
bSetActive = TRUE;
else
bSetActive = FALSE;
pDoc->m_bAutoDelete = FALSE; //设置标志,这样当视图销毁时不会删除文档
((CView*)m_wndSplitter.GetPane(row, col))->DestroyWindow(); //删除存在的视图
pDoc->m_bAutoDelete = TRUE; //设回默认的标志
//创建新视图
context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
//m_wndSplitter.DeleteView(0, 1);
m_wndSplitter.CreateView(row, col, pViewClass, size, &context);
CView *pNewView = (CView*)m_wndSplitter.GetPane(row, col);
if (bSetActive == TRUE)
this->SetActiveView(pNewView);
m_wndSplitter.RecalcLayout(); //重新计算位置
// m_wndSplitter.GetPane(row,col)->SendMessage(WM_PAINT);
return TRUE;
}