没有SetActiveView的话,GetActiveView是会返回NULL的
把代码放在document里面,要更新界面的话用UpdateAllViews

解决方案 »

  1.   

    提供一个文档,供参考:关于获得MFC窗口其它类指针的方法(CSDN) 
    访问应用程序的其它类 获得CWinApp: 
    -在CMainFrame,CChildFrame,CDocument,CView中直接调用AfxGetApp()或用theApp 
    -在其它类中只能用AfxGetApp() 获得CMainFrame: 
    -在CMinApp中用AfxGetMainWnd()或者m_pMainWnd 
    -在CChildFrame中可用GetParentFrame() 
    -在其它类中用AfxGetMainWnd() 获得CChildFrame: 
    -在CView中用GetParentFrame() 
    -在CMainFrame中用MDIGetActive()或GetActiveFrame() 
    -在其它类中用AfxGetMainWnd()->MDIGetActive()或AfxGetMainWnd()->GetActiveFrame() 获得CDocument: 
    -在CView中用GetDocument() 
    -在CChildFrame中用GetActiveView()->GetDocument() 
    -在CMainFrame中用 
      -if SDI:GetActiveView()->GetDocument() 
      -if MDI:MDIGetActive()->GetActiveView()->GetDocument() 
    -在其它类中 
      -if SDI:AfxGetMainWnd()->GetActiveView()->GetDocument() 
      -if 
    MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView()->GetDocument() 获得CView: 
    -在CDocument中 POSITION pos = GetFirstViewPosition();GetNextView(pos) 
    -在CChildFrame中 GetActiveView() 
    -在CMainFrame中 
      -if SDI:GetActiveView() 
      -if MDI:MDIGetActive()->GetActiveView() 
    -在其它类中 
      -if SDI:AfxGetMainWnd()->GetActiveView() 
      -if MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView() 
      

  2.   

    补充一点:
    不过要注意在doc中要取得view的指针C*View要注意类C*View声明的问题, 
    因为默认情况下,mfc在*View.h中已经包含了*Doc.h,如果在*Doc.h中包含 
    *View.h,就会引起嵌套包含问题,这样要在*Doc.h中加入 class C*View; 
    而在*Doc.cpp中加入 #include "*View.h" 这段话的意思应该懂的吧。
      

  3.   

    谢谢大家的恢复,我找到问题了!
    是因为这
    if( !pView->IsKindOf(pClass) )
            {
                //AfxMessageBox( "Connot locate the View."); 
                return NULL;
            }删了就行了!!