Solved

How to get Main View from Mainframe

Posted on 2000-02-22
6
563 Views
Last Modified: 2013-11-20
I have writtten a n MDI app. Now i want to access my default or first view/window from the Mainframe. I have created many Child window any of which i can access by thier frame pointers but how can i get the frame pointer of the default or first view/window.
0
Comment
Question by:kakamna
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2549227
Call CMDIFrameWnd::MDIGetActive() to get the currently active CMDIChildWnd.
0
 

Author Comment

by:kakamna
ID: 2556944
What i want is that how can i get the main window or frame cordinates so that i can get the co-ordinates of all the child windows with respect to the main window co-ordinate. I want to save the postion of all the child window relative to the main window when the ap is closed and are restores when ever the aplication is being started again.
0
 
LVL 8

Accepted Solution

by:
VinExpert earned 100 total points
ID: 2557887
Hi,

I assume that Ur
App class is CTestApp
main/default view is CTestView

Say U want to access a variable say intVal which is a int from the CTestView in mainframe.

Follow the steps.

1. Open the TestView.cpp. Remove the include headers for the TestView.h and TestDoc.h

2. Open MainFrame.h and include the TestView.h
3. Open the Test.h and include the TestDoc.h
4. Open Test.cpp go to InitInstance(), there U will find the default view's document template. Remove the first line i,e,, remove
CMultiDocTemplate* pDocTemplate;
and add it as the public member in Test.h
5. Open the mainfrm.h and add the following function as public:
BOOL FrameCreateOrActivate(CMDIFrameWnd* pMDIFrameWnd, CDocTemplate* pTemplate,CRuntimeClass* pViewClass);

6. Then open the mainfrm.cpp and add the function as
BOOL CMainFrame::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))
                  {                        
                        ((CTestView *)pView)->intVal = 10;                  
                        return TRUE;
                  }
            }

      }
      else
      {
            //No views So dont handle anything
      }
      if(pNewFrameWnd == NULL)
            return FALSE;

      return TRUE;
}

7. Whenever u want to access that variable just call it as
CTestApp *pApp = (CTestApp *)AfxGetApp();
      FrameCreateOrActivate((CMDIFrameWnd*)AfxGetMainWnd(), pApp->pDocTemplate,(RUNTIME_CLASS(CTestView)));

Thats it. Here I have shown U to access only one variable. If U want to access more that one, then just modify the function little bit to handle that. In the similar way u can call the functions too.

Hope this helps.
VinExpert
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:VinExpert
ID: 2557951
Hi,

One more simple method.

1. Open the TestView.cpp, Remove the TestView.h and TestDoc.h includes.
2. Open the MainFrm.h and include TestView.h
3. Open the Test.h and include TestDoc.h
4. In the MainFrm.h have the pointer as
CTestView *m_pMainView;
5. In the mainframe's constuctor set it to NULL as
m_pMainView = NULL;
6. Open the TestView.cpp, include MainFrm.h and in one of the initialisation functions say OnDraw put the following line
((CMainFrame *)AfxGetMainWnd())->m_MainView = this;

7. Then U can access all the variables and functions of that view class from the mainframe using m_pMainView pointer.

Try it out.
VinExpert
0
 

Author Comment

by:kakamna
ID: 2564165
VineExpert is really a expert.
Thanx
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2564198
Hi,

No, No, No such comments plz :-).

VinExpert
(Not VineExpert)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now