从一个视图类取得另一视图类的指针

来源:互联网 发布:2012年网络作家富豪榜 编辑:程序博客网 时间:2024/06/03 13:34

(假设要从CTestAView中取得指向其它视图类的指针)
 CView* CTestAView::GetView(CRuntimeClass* pClass) 
 {    CTestDoc* pDoc=(CTestDoc*)GetDocument();   
   CView* pView;  
     POSITION pos=pDoc->GetFirstViewPosition();    
   while(pos!=NULL)    {  
      pView=pDoc->GetNextView(pos);   
        if(pView->IsKindOf(pClass))        
       break;  
}      
 if(!pView->IsKindOf(pClass))  
         return  NULL;    
   return pView;
}    
有了此函数;当要从CTestAView中取得CTestBView的指针时,只需如下:    CTestBView* pTestbView=(CTestBView*)GetView(RUNTIME_CLASS(CTestBView));

原创粉丝点击