譬如说我在CXXXDoc类中加入了个处理菜单命令的函数,但是我需要控制CXXXLeftView和CXXXView来做一些事,怎么才能做到?我知道在CXXXView中可以通过GetDocument()得到CXXXDoc的指针,但是如何在CXXXDoc中得到CXXXView的指针呢?

解决方案 »

  1.   

    (CXXXView *) pXXX = (CXXXView *)GetActiveView();
      

  2.   

    CDocument::GetFirstViewPosition , 
    CDocument::GetNextView 
    前提是view被调用过CDocument::AddView加入到了doc
    的viewlist中,文档模板中的那个view是自动被加上的,
    因此可以用以上方法取得
    如果是splitwnd,可以用CSplitterWnd::GetPane 取得
      

  3.   

    你指的是不是用CSplitterWnd拆分出来视图,用GetPane可以获得,用法参照MSDN
      

  4.   

    if you use CplitterWnd,then you can get View point from Getpane,such as
    //得到右视图指针
    CRightView* CMainFrame::GetRightPane()
    {
    CWnd* pWnd = wndSplitter.GetPane(0, 1);
    CRightView* pView = DYNAMIC_DOWNCAST(CRightView, pWnd);
    return pView;
    }
    //得到左视图指针
    CLeftView* CMainFrame::GetLeftPane()
    {
    CWnd* pWnd = wndSplitter.GetPane(0, 0);
    CLeftView* pView = DYNAMIC_DOWNCAST(CLeftView, pWnd);
    return pView;
    }
    in your CXDoc;
    CMainFrame*pFrm=(CMainFrame*)AfxGetMainWnd();
    CLeftView*pLeftView=(CLeftView*)pFrm->GetLeftPane();