I wrote the following procedure to activate views programatically. It's a bit specialised, but I hope it might give you some useful clues. The bit underneath the comment "//There is already a View displaying this parent..." activates the view pointed to by pView.
CKernelView* CMainFrame::ActivateView(CModel* pParentModel)
{
//Activate new or existing view containing pParentModel
CKernelView \*pView, \*pActiveView;
CWnd\* pBar;
CMDIFrameWnd \*pFrame;
CMDIChildWnd \*pChild;
pBar = GetDlgItem(IDD\_NAVIGATOR\_BAR);
//Get a pointer to the active view (there are three stages to this)
pFrame = (CMDIFrameWnd\*)AfxGetApp()->m\_pMainWnd; //Get a pointer to the active MDI window
pChild = (CMDIChildWnd \*) pFrame->GetActiveFrame(); //Get the active MDI child window.
pActiveView = (CKernelView\*)pChild->GetActiveView(); //Get the View attached to the active MDI child window
if (pActiveView->m\_pParentModel == pParentModel)
pView = pActiveView; //The required parent model is already in the active view
else if (pParentModel->m\_pShadow != NULL)
{
//There is already a View displaying this parent, activate its frame
pView = pParentModel->m\_pShadow->m\_pView;
pFrame = (CMDIFrameWnd\*)pView->GetParentFrame();
pFrame->ActivateFrame(SW\_RESTORE);
}
else if (pBar->IsDlgButtonChecked(IDC\_TRACK\_NEW))
pView = pParentModel->OpenView(m\_pDocViewed, pParentModel->m\_PlantFlag); //Open new window
else
{
//Reuse current window
pView = pActiveView;
pView->ChangeModel(pParentModel);
}
return pView;
}
Best Regards Cliff -- modified at 17:36 Monday 3rd July, 2006