?
Solved

How to get Main View from Mainframe

Posted on 2000-02-22
6
Medium Priority
?
616 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 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