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

Multiple document interface(MDI)

actually i want to come out with a frame which have 2 views(each view tie to their respective document-b'cos the data shown on one view is different from the others). these views are only shown when the user requests it. however these 2 views are able to keep refreshing(real-time) their content(document data) when they are hidden or showing.
(note : currently i only have one frame with one view one document. And the view are able to data refresh in real-time)
  • 2
1 Solution
in the mainframe window put menu entries to change the view:

put this in the menu entry when u want to change the view

      long m_nCurrentExample;

/* gets the current view */      
      CView* pOldActiveView = GetActiveView();
            ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentExample);

      CRuntimeClass* pNewViewClass;      
      pNewViewClass = RUNTIME_CLASS(CShayView); // here set the new view class

      CCreateContext context;
      context.m_pNewViewClass = pNewViewClass;
      context.m_pCurrentDoc = GetActiveDocument();
/* create the new view and attach it to the mainframe */
      CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
      if (pNewView != NULL)
            // the new view is there, but invisible and not active...

            // finally destroy the old view...

there is slight problem in your answer...

1. You have to destroy the old view before you activate the new one. Because when you destroy a view, it sets the Active view of the frame to be NULL.

void CView::OnDestroy()
      CFrameWnd* pFrame = GetParentFrame();
      if (pFrame != NULL && pFrame->GetActiveView() == this)
            pFrame->SetActiveView(NULL);    // deactivate during death

2. When view is being destroyed, DOC/VIEW architecture can delete your document also.
So you have to protect against that when you r destroying view. Set m_bAutoDelete to FALSE before you make destroywindow call and then reinstate the variable state.

Tang... the answer to this question is same as the one you asked before for SDI..

naveenkohli ! thank u very much.
i didn't know that, cause i m using it for SDI, and it works, never tried it for MDI.

thank u
swtang72Author Commented:
i need to take some time to 'digest' the sample project that u 've given to me. so that i can decide how much point i should reward u. pls be patient.
but anyway the your info is quite sufficient and at the same time ,very fast reponse !!
thank u.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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