Use the following functions to navigate between application, View, document and frame objects e.g. AfxGetApp(), AfxGetMainWnd(), GetActiveView(), GetDocument().
1. You can get access to the application object from any other classes using
CmyApp * pApp = (CMyApp*)AfxGetApp(); where CMyApp is your application class dertived from CWinApp.
2. You can access the main window of the application using one of the following depending on SDI or MDI application:
CMyFrame * pFrame = AfxGetApp()->m_pMainWnd;
or
CMyFrame * pFrame = AfxGetMainWnd();
or
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
3. To access the active view object from the Dialog class or from other classes:
#include "CMyProgramView.h"
CMyFrame * pFrame = AfxGetApp()->m_pMainWnd;
if (pFrame)
{
CMyProgramView *pView = (CMyProgramView *) pFrame->GetActiveView();
if (pView)
{
// here you access the public members of the CmyProgramView object
}
else
{
// error
}
}
-obislavu-