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;
            else
                  pNewActiveView = (CView*)new CSectionForm;


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

      SetActiveView(pNewActiveView);
      pNewActiveView->ShowWindow(SW_SHOW);
      pOldActiveView->ShowWindow(SW_HIDE);
      pOldActiveView->SetDlgCtrlID(
            pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CCourseForm) ?
            IDW_COURSE_FORM : IDW_SECTION_FORM);
      pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
      RecalcLayout();
}

Thanks
DegraveAsked:
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.

bhatCommented:
Hi ,
I believe U have got a menu items for each formview.
 
Supposse the on Command for a particular forma view
say
::OnDisplayForm1
{
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();
ASSERT(pDoc != NULL);
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while(pos)
{
      pView = pDoc->GetNextView(pos);
      if(pView->IsKindOf(pViewClass))
      {                                                  pView->GetParentFrame()->ActivateFrame();                                        (pView->GetParent())->ShowWindow(SW_RESTORE);
                    return TRUE;
      }
}
pNewFrameWnd = ((CMDIChildWnd*)pTemplate->CreateNewFrame(pDoc,NULL));
            pTemplate->InitialUpdateFrame(pNewFrameWnd,pDoc);
}
else
{
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.


0

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
C++

From novice to tech pro — start learning today.