Click here to Skip to main content
15,900,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Everyone and thanks in advance,

I am making an mdi application.

I have an event handler in the mainframe, which is supposed to call a function in the View class,
How do i do that, At the moment, what am doing is -

I create a function in the MyApp class (main class) say Callviewfuntion();
then in the Mainframe, I call - theApp.Callviewfuntion();

//Then in the App function i do this
C++
CMyView* pView = (CMyView*)RUNTIME_CLASS(MyView);
pView->MyFuntion();

I am using the application class as the bridge between CMainFrame, and the CMyView - I guess I am suppose to use the Doc class to get the nextview(), but please show me.
Posted
Updated 3-Nov-11 22:26pm
v2

CFrameWnd::GetActiveView documentation[^] fetures an example of retrieving the active view pointer in a MDI application.
 
Share this answer
 
See also :) :
C++
void CMainFrame::ProcessDocsAndViewsCalls(CYourDocCallParameter* pcDocPar,
                                          CYourViewCallParameter* pcViewPar)
{
  CWinApp* pcWinApp = AfxGetApp();
  // Templates loop
  POSITION pos(pcWinApp->GetFirstDocTemplatePosition());
  while (pos) {
    CDocTemplate* pcTemplate(pcWinApp->GetNextDocTemplate(pos));
    ASSERT(pcTemplate && pcTemplate->IsKindOf(RUNTIME_CLASS(CDocTemplate)));
    // Docs loop
    POSITION posDoc(pcTemplate->GetFirstDocPosition());
    while (posDoc) {
      CDocument* pcDoc(pcTemplate->GetNextDoc(posDoc));
      ASSERT(pcDoc);
      // Filter your docs here:
      if (pcDoc->IsKindOf(RUNTIME_CLASS(CYourDoc))) {
        CYourDoc* pcYourDoc((CYourDoc*) pcDoc);
        pcYourDoc->TakeIt(pcDocPar); // your target doc call
        // Views loop
        POSITION posView(pcYourDoc->GetFirstViewPosition());
        while (posView) {
          CView* pcView(pcYourDoc->GetNextView(posView));
          ASSERT(pcView);
          // Filter your views here:
          if (pcView->IsKindOf(RUNTIME_CLASS(CYourView))) {
            CYourView* pcYourView((CYourView*) pcView);
            pcYourView->TakeIt(pcViewPar); // your target view call
          }
        }
      }
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900