• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Any solution for the following problem

I want to add two views in the certain document in MDI application.
in the *App.cpp, I add the following codes to share the same doc.
      // create main MDI Frame window
      CMainFrame* pMainFrame = new CMainFrame;
      if (!pMainFrame->LoadFrame(IDR_MeritTYPE))
            return FALSE;

      m_pMainWnd = pMainFrame;

      m_pElectricityMatchDocTemplate = new CMultiDocTemplate(IDR_MERITMATCH,
            RUNTIME_CLASS(CMatchFrame), // custom MDI child frame


      m_pThermalMatchDocTemplate = new CMultiDocTemplate(IDR_MERITMATCH,
            RUNTIME_CLASS(CMatchFrame), // custom MDI child frame

when the program run until the following code:
      CDocument* pDoc = NULL;// m_pMatchDocTemplate->OpenDocumentFile(NULL,0);
      m_pElectricityMatchView = CElectricityMatchView::GetView();   //the pointer to the view is empty, why????

      ASSERT(m_pElectricityMatchView != NULL);
The function of GetView() in details:
            CElectricityMatchView* CElectricityMatchView::GetView()

              CMDIChildWnd * pChild =
               if ( !pChild )
              AfxMessageBox("pChild Error!");
                   return NULL;

               CView * pView = pChild->GetActiveView();

               if ( !pView )
              AfxMessageBox("pView Error!");
                  return NULL;

             // Fail if view is of wrong kind
             if ( ! pView->IsKindOf( RUNTIME_CLASS(CElectricityMatchView) ) )
              AfxMessageBox("pView->IsKindOf Error!");
                  return NULL;
              return (CElectricityMatchView*) pView;
I can't get the view of child window. why?
is anything wrong with the above code? any solution?
1 Solution
junhongukAuthor Commented:
I have already sovled the problem. There is something wrong with my code.

modified the specific code as follows:

    CDocument* pDoc = m_pMatchDocTemplate->OpenDocumentFile(NULL);
     m_pElectricityMatchView = CElectricityMatchView::GetView();  

It will get the pointer of the view.


Closed, 300 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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