• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

How can I access member variables in CMyView from popup dialogs?

I have an SDI FormView application with popup dialogs.  I would like to have access to the member variables on the main dialog from the popup dialogs.

How can I reference the CMyView (FormView) in my popup dialogs?

Could you please give me an example of how I could do this.

Thank you.
0
drodgers
Asked:
drodgers
  • 2
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

U can do it in two ways.
1. maitain the variables in the app class and acces it using AfxGetApp()...
2. If pop up dialogs are childs of Ur main window, then in the child dialog use
GetParent()->m_ParentVar;
where m_ParentVar i sthe variable in the parent class.

Hope it helps.
VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

U can maintain those variables in the mainframe also.
say a variable m_ParentVar.
If it is declared in mainframe.h, then to access it
CMainFrame* l_pMain = (CMainFrame*)AfxGetMainWnd();
l_pMain->m_ParentVar will give u that variable.

If it is declared in app.h and Ur App class is CMyApp, then to access it
CMyApp *pApp = (CMyApp *)AfxGetApp();
pApp->m_ParentVar will give u that variable.

If the variable is one dialog and it pops up another dialog, and u want to access that variable from the poped up dialog, then
in the poped up dialog
GetParent()->m_ParentVar will give u that variable. or u can also use this->GetParent()->m_ParentVar to access it.

Try it out.
VinExpert
0
 
drodgersAuthor Commented:
Thank you for your help VinExpert.  I am still having a hard time with the member variables in my CView class.  I think it's because my CFormView is protected and I don't know how to get around that.  Thanks again.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now