[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

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
0
Degrave
Asked:
Degrave
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now