在主框架窗口中为每个视添加一个指针成员变量。然后用
((CMainFrame*)AfxGetApp()->m_pMainWnd)->...(指向你的视窗口的成员指针)就可以在任何地方引用你的视了。

解决方案 »

  1.   

    可我的View是在程序序中动态分割的呀!m_pMainWnd中没有视窗口的成员指针!
    我菜!
    能不能不用动态分割创建窗口!
      

  2.   

    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    // TODO: Add your specialized code here and/or call the base class
    CRect rect;
    GetClientRect(&rect);
    int width = rect.Width();
    int height = rect.Height(); if (!m_wndSplitter.CreateStatic(this, 1, 2))
    return FALSE; if (!m_wndSplitter.CreateView(0, 0,
    RUNTIME_CLASS(CInfoManagerView), CSize(width/3, height), pContext))
    {
    TRACE0("Failed to create first pane\n");
    return FALSE;
    } if (!m_wndSplitter2.CreateStatic(
    &m_wndSplitter,     // our parent window is the first splitter
    2, 1,               // the new splitter is 2 rows, 1 column
    WS_CHILD | WS_VISIBLE ,  // style, WS_BORDER is needed
    m_wndSplitter.IdFromRowCol(0, 1)  ))
    {
    TRACE0("Failed to create nested splitter\n");
    return FALSE;
    }
    if (!m_wndSplitter2.CreateView(0, 0,
    RUNTIME_CLASS(CInfoView), CSize(2*width/3, 2*height/3), pContext))
    {
    TRACE0("Failed to create second pane\n");
    return FALSE;
    } if (!m_wndSplitter3.CreateStatic(
    &m_wndSplitter2,     // our parent window is the first splitter
    1, 2,               // the new splitter is 1 rows, 2 column
    WS_CHILD | WS_VISIBLE ,  // style, WS_BORDER is needed
    m_wndSplitter2.IdFromRowCol(1, 0)  ))
    {
    TRACE0("Failed to create nested splitter\n");
    return FALSE;
    }
    if (!m_wndSplitter3.CreateView(0, 0,
    RUNTIME_CLASS(CLetterView), CSize(85*width/100, height/3), pContext))
    {
    TRACE0("Failed to create second pane\n");
    return FALSE;
    }
    if (!m_wndSplitter3.CreateView(0, 1,
    RUNTIME_CLASS(CFileInfoView), CSize(15*width/100, height/3), pContext))
    {
    TRACE0("Failed to create second pane\n");
    return FALSE;
    }
    m_ManagerView = (CInfoManagerView *)m_wndSplitter.GetPane(0,0);
    m_InfoView    = (CInfoView *)m_wndSplitter2.GetPane(0,0);
    m_LetterView  = (CLetterView *)m_wndSplitter3.GetPane(0,0);
    m_FileInfoView    = (CFileInfoView *)m_wndSplitter3.GetPane(0,1); ShowWindow(SW_SHOWMAXIMIZED); return TRUE;
    }
      

  3.   

    找到第一个指定类型的视图
    CView* CDoorCtrlApp::FindView(CRuntimeClass* pViewClass)
    {
    POSITION posDocTemplate=GetFirstDocTemplatePosition();
    POSITION posDocument=NULL;
    POSITION posView=NULL;
    CDocTemplate* pDocTemplate=NULL;
    CDocument* pDocument=NULL;
    CView* pView=NULL;
    while(posDocTemplate){
    pDocTemplate=GetNextDocTemplate(posDocTemplate);
    posDocument=pDocTemplate->GetFirstDocPosition();
    while(posDocument){
    pDocument=pDocTemplate->GetNextDoc(posDocument);
    posView=pDocument->GetFirstViewPosition();
    while(posView){
    pView=pDocument->GetNextView(posView);
    if(pView->IsKindOf(pViewClass))
    return pView;
    }
    }
    }
    return NULL;
    }