Passing values between dialogs.

I have an SDI application with a formview.  I have popup modeless and modal dialogs. I would like to share variables between these dialogs.

Would you please give me an example of how I can pass variables.

Thank you

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

fstabConnect With a Mentor Commented:
You can use the view's document for this purpose. For eg. you may want to have a status variable or flag -

1. Declare the variable in the CDocument derived class

class CMyDoc:public CDocument {
public :
int flag;

2. Include the header file in your popup modeless dialog class CPP files

3. Use the GetDocument method to get a pointer to the document and access the variable flag in the following manner :

CMyView *pView = (CMyView *) GetActiveView();
CMyDoc *pDoc = (CMyDoc *) pView->GetDocument();

int flag = pDoc->flag;

Hope this helps.
You can either create a global variable, or declare the variable in one class, and pass a pointer to the other class.
fstab: Please post as comment, until an answer is accepted. Otherwise, the question is locked, keeping other experts from viewing it.
That's the basic idea - if I think I have the answer I should post it as an answer - other experts can still view it and post a comment .. in case my answer is rejected the person who posted the correct answer as a comment can still get points .. its all in the hands of (in this case) ducksoup ..
Vinayak KumbarSr Program ManagerCommented:

The best way(and the commonly used method) is to declare those variables in App class and access them anywhere in the application.

If Ur application is Test

then declare the flag(for ex) m_bFlag in CTestApp.h

Then U can access it as

((CTestApp *)AfxGetApp())->m_bFlag

Try it out.
All Courses

From novice to tech pro — start learning today.