Solved

How to get Main View from Mainframe

Posted on 2000-02-22
6
606 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

688 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