可以在从CView类派生出的CMyView1 ,CMyView2添加成员函数
/*------------------------------------------------------------------------------
* 函数名: GetView
* 功能: 获取视图指针
* BY: Kevin
* 输入参数: 要指向视图的指针 CRuntimeClass*pClass
* 返回参数: CView*
* 备注: 2010-03-24
* 修改:
*----------------------------------------------------------------------------*/
CView* CMyView1 ::GetView(CRuntimeClass*pClass)
{
CMyDoc* pDoc=(CMyDoc*)GetDocument();
CView* pView;
POSITION pos=pDoc->GetFirstViewPosition();
while(pos!=NULL)
{
pView=pDoc->GetNextView(pos);
if( pView->IsKindOf(pClass) )
{
break;
}
}
if(!pView->IsKindOf(pClass))
{
AfxMessageBox(_T("Cannot locate the View."));
return NULL;
}
return pView;
}
在调用时 只要这样
CMyView2*pTestBView=
(CMyView2*)GetView(RUNTIME_CLASS(CMyView2));