Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing Active View

Changing Active View

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Tom_
    wrote on last edited by
    #1

    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

    V C 2 Replies Last reply
    0
    • _ _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

      V Offline
      V Offline
      Viorel
      wrote on last edited by
      #2

      I would suggest you the MDIActivate member of CMDIFrameWnd class. I hope it works.

      _ 1 Reply Last reply
      0
      • V Viorel

        I would suggest you the MDIActivate member of CMDIFrameWnd class. I hope it works.

        _ Offline
        _ Offline
        _Tom_
        wrote on last edited by
        #3

        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

        V 1 Reply Last reply
        0
        • _ _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

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          I suppose the parameter of MDIActivate should be a frame window (CMDIChildWnd) which contains your view. Try this:

          CWnd * p = pView->GetParent();
          ASSERT_KINDOF(CMDIChildWnd, p);
          pMainFrm->MDIActivate(p);
          
          1 Reply Last reply
          0
          • _ _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

            C Offline
            C Offline
            Cliff Hatch
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups