Solved

How to get Main View from Mainframe

Posted on 2000-02-22
6
552 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

13 Experts available now in Live!

Get 1:1 Help Now