Search code examples
c++mfcmdidocument-view

MDI MFC VC++ how to switch views within mainframe


I am making MDI application , and without using splitter my document has multiple views. Now i want to change the document view from the MainFrame of an application...

here it is what i am doing , i have outlookbar with some menu buttons, when user will click those buttons then i will show CFormView inside the document as a child instead of popup dialog. Now i dont know how to change the view from MainFrame where the menu handler has been written.

Kindly suggest any tip if you know any...there are more than 5 different views and 4 of them are CFormView.

MainFrame ->MenuhandlerFunction (Menu Clicks)

MenuHandlerFunction -> Open New Document with New View Based on CFormView

(total 5 different CFormView and their handlers inside MainFrame Written)


Solution

  • I'm not very sure how you select which view to display, but here is some code to iterate through the views of the current document in your MainFrame:

    EDIT: modified code for MDI

    CMDIChildWnd *pChild = (CMDIChildWnd*)GetActiveFrame();  // EDIT: added line
    CDocument *pDoc = pChild->GetActiveDocument();           // EDIT: added pChild->
    POSITION pos = pDoc->GetFirstViewPosition();
    while (pos != NULL)
    {   CView* pView = GetNextView(pos);
        // if this is the view you want to activate
        //     pChild->SetActiveView(pView);                 // EDIT: added pChild->
    }