Hello, the codegurus around the world.;) I often use this function from "HOW-TO VISUAL C++ 4.0" by Scott ? to change the active view on MDI application.
void CMainFrame::SwitchToView(CDocTemplate* pTemplate, CRuntimeClass* pViewClass)
{
CMDIChildWnd* pMDIActive = MDIGetActive();
CDocument* pDoc = pMDIActive->GetActiveDocument();
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while(pos != NULL)
{
pView = pDoc->GetNextView(pos);
if(pView->IsKindOf(pViewClass))
{
//the requested view has already been created; show it
pView->GetParentFrame()->ActivateFrame();
return;
}
}
//The requested view hasn't been created yet
CMDIChildWnd\* pNewFrame = (CMDIChildWnd\*)
pTemplate->CreateNewFrame(pDoc, NULL);
if(pNewFrame == NULL) return;
pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
}
and call this function anywhere like this.
((CMainFrame\*)AfxGetMainWnd())->SwitchToView(theApp.m\_pAppTemplate,
RUNTIME\_CLASS(CAppView));
Have a nice day! -Masaaki Onishi-