In my program I have made a Dioalog box where the user types in some data and I want to be able to send this data to a variable in the CMyProgramView class. But all the methods I have tried so far do not work. Any suggestions??
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();
// 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
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.