How can I switch to an other Formview in a SDI application

I want to make an application with several Formviews. In the tutorial sample "DAOenroll" from the MSDN, you can do it. When I use the same function (SwitchToForm(int nForm), it doesn't work.
Can I switch between formviews like you do it with dialogboxes (With member function ".DoModal")???
This is the SwitchToForm-function:

void CMainFrame::SwitchToForm(int nForm)
      CView* pOldActiveView = GetActiveView();
      CView* pNewActiveView = (CView*)GetDlgItem(nForm);
      if (pNewActiveView == NULL)
            if (nForm == IDW_COURSE_FORM)
                  pNewActiveView = (CView*)new CCourseForm;
                  pNewActiveView = (CView*)new CSectionForm;

            CCreateContext context;
            context.m_pCurrentDoc = pOldActiveView->GetDocument();
            pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
                  this, nForm, &context);

            pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CCourseForm) ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi ,
I believe U have got a menu items for each formview.
Supposse the on Command for a particular forma view
In this function call the  FrameCreateOrActivate(......)
with pointer to the MDi frame,pointer to document template
Runtime class

If this function is in APP class
then mdiframe pointer can be ((CMDIFrameWnd*)m_pMainWnd),
runtime class  = ((RUNTIME_CLASS(CYourFormview)))


BOOL FrameCreateOrActivate(CMDIFrameWnd* pMDIFrameWnd,CDocTemplate* pTemplate,                                                                                    CRuntimeClass* pViewClass)
CMDIChildWnd* pMDIActiveWnd = (CMDIChildWnd*)pMDIFrameWnd->MDIGetActive();
CMDIChildWnd* pNewFrameWnd = NULL;      if(pMDIActiveWnd != NULL)
CDocument* pDoc = pMDIActiveWnd->GetActiveDocument();
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
      pView = pDoc->GetNextView(pos);
      {                                                  pView->GetParentFrame()->ActivateFrame();                                        (pView->GetParent())->ShowWindow(SW_RESTORE);
                    return TRUE;
pNewFrameWnd = ((CMDIChildWnd*)pTemplate->CreateNewFrame(pDoc,NULL));
pNewFrameWnd = ((CMDIChildWnd*) pTemplate->OpenDocumentFile(NULL));
if(pNewFrameWnd == NULL)
      return FALSE;

      return TRUE;

this function will check if the view is open it will activate it else
it will open the view.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.