如题,我想通过判断文档中的一个文件名是否相同来切换,结果没有成功?怎么办?
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;
}
}
}
}
}
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;
}
}
}
}
}
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);
AfxGetApp()->m_pMainWnd为框架窗口指针
在框架窗口中:CFrameWnd::GetActiveDocument得到当前活动文档指针
在框架窗口中:CFrameWnd::GetActiveView得到当前活动视指针
在视中:CView::GetDocument得到对应的文档指针
在文档中:CDocument::GetFirstViewPosition,CDocument::GetNextView用来遍历所有和文档关联的视。
在文档中:CDocument::GetDocTemplate得到文档模板指针
在多文档界面中:CMDIFrameWnd::MDIGetActive得到当前活动的MDI子窗口