如题,我想通过判断文档中的一个文件名是否相同来切换,结果没有成功?怎么办?
void CLoopWareApp::FindMyChildWnd(CString strBmpFileName)
{
POSITION pos1,pos2,pos3;
pos1=GetFirstDocTemplatePosition();
if(NULL!=pos1)
{
CLoopWareDoc *pDoc;
CDocTemplate *pDocTemplate = GetNextDocTemplate(pos1);
pos2=pDocTemplate->GetFirstDocPosition();
while(NULL!=pos2)
{
pDoc = (CLoopWareDoc *)pDocTemplate->GetNextDoc(pos2);
if(NULL!=pDoc)
{
if(pDoc->m_strPictureFileName == strBmpFileName)  // 根据这个文件判断
{
pos3=pDoc->GetFirstViewPosition();
if(NULL!=pos3)
{
CMainFrame* pMainFrame = (CMainFrame *)GetMainWnd();
CView *pNewView=pDoc->GetNextView(pos3);
if(NULL!=pNewView)
{
pMainFrame->SetActiveView(pNewView);  // 执行后没有反应,并且退出程序时有错误发生
}
}
return;
}
}
}

}
}

解决方案 »

  1.   

    CString strTitle; // 需要比较的名称
    CFrameWnd* pFindFrame = NULL;
    POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
    while ( pos )
    {
    CDocTemplate* pDocTemplate = AfxGetApp()->GetNextDocTemplate(pos);
    POSITION posDoc = pDocTemplate->GetFirstDocPosition();
    if ( !posDoc )
    continue;
    CDocument* pDoc = pDocTemplate->GetNextDoc(posDoc);
    if ( !pDoc || pDoc->GetTitle() != strTitle /* || pDoc->GetPathName() != strTitle*/) // 1.比较方式,也可以采用2方式比较
    continue;
    POSITION posView = pDoc->GetFirstViewPosition();
    if ( !posView )
    continue;
    CView* pView = pDoc->GetNextView(posView);
    if ( !pView )
    continue;
    CFrameWnd* pFrame = pView->GetParentFrame();
    if ( !pFrame || !pFrame->GetSafeHwnd() )
    continue;
    CString strWindowText;
    pFrame->GetWindowText(strWindowText);
    if ( strWindowText == strTitle ) // 2.比较方式,也可以采用1方式比较
    {
    pFindFrame = pFrame;
    break;
    }
    }
    if ( pFindFrame ) pFindFrame->ActivateFrame(SW_SHOWNORMAL);
      

  2.   

    全局函数AfxGetApp可以得到CWinApp应用类指针 
    AfxGetApp()->m_pMainWnd为框架窗口指针 
    在框架窗口中:CFrameWnd::GetActiveDocument得到当前活动文档指针 
    在框架窗口中:CFrameWnd::GetActiveView得到当前活动视指针 
    在视中:CView::GetDocument得到对应的文档指针 
    在文档中:CDocument::GetFirstViewPosition,CDocument::GetNextView用来遍历所有和文档关联的视。 
    在文档中:CDocument::GetDocTemplate得到文档模板指针 
    在多文档界面中:CMDIFrameWnd::MDIGetActive得到当前活动的MDI子窗口 
      

  3.   

    http://blog.chinaunix.net/u2/63021/showart_512742.html
      

  4.   

    hahaking119同志方案的要点是从视中找到对应的child,然后激活这个child,这是精华的所在。经验证方案可行,所以本贴再加20分,全部送给hahaking119同志,实在惭愧,本人可用分不足50分。
      

  5.   

    为了突出宣传hahaking119同志,其他同志在本贴就不给分了,多谢大家的捧场,其他帖子再见再送分。
      

  6.   

    视中如何直接取框架?必须通过App吗?
      

  7.   

    直接AfxGetMainWnd,如果通过ChildFrame可以调用GetParentFrame