Changing Active View
-
Dear All, I have a MDI application and I'm currently trying to programmatically change the active view. So in sort I have a combo box on my toolbar which list the views currently open. When I select a different view in this combobox I want that view to come into focus. Basically it should do exactly the same as selecting the view from the 'Window' main menu option. I have tried sending the WM_MDIACTIVATE message to the main frame but this doesn't seem to work. Any suggestions would be gratefully received. Many thanks Tom
-
Dear All, I have a MDI application and I'm currently trying to programmatically change the active view. So in sort I have a combo box on my toolbar which list the views currently open. When I select a different view in this combobox I want that view to come into focus. Basically it should do exactly the same as selecting the view from the 'Window' main menu option. I have tried sending the WM_MDIACTIVATE message to the main frame but this doesn't seem to work. Any suggestions would be gratefully received. Many thanks Tom
-
Hi Thanks for the suggestion of using MDIActivate, unfortunately this doesn't seem to do trick when I call the following: pMainFrm->MDIActivate((CWnd*)pView); Where pView is a pointer to the view I want to activate and bring to the front of all other view windows. I was wondering if I should be casting here and whether I had used the function correctly. Thanks Tom
-
Hi Thanks for the suggestion of using MDIActivate, unfortunately this doesn't seem to do trick when I call the following: pMainFrm->MDIActivate((CWnd*)pView); Where pView is a pointer to the view I want to activate and bring to the front of all other view windows. I was wondering if I should be casting here and whether I had used the function correctly. Thanks Tom
-
Dear All, I have a MDI application and I'm currently trying to programmatically change the active view. So in sort I have a combo box on my toolbar which list the views currently open. When I select a different view in this combobox I want that view to come into focus. Basically it should do exactly the same as selecting the view from the 'Window' main menu option. I have tried sending the WM_MDIACTIVATE message to the main frame but this doesn't seem to work. Any suggestions would be gratefully received. Many thanks Tom
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 pParentModelCKernelView \*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