views:

31

answers:

1

I want to communicate between two or more dialog windows,when i say communicate It means that I want to use the variables and functions in all dialog boxes with values updated.. So what I did is created three main Dialog boxes,Considering 1 dialog window as main window where it can have variables and functions and I created a pointer variable for the maindialog in other windows..to access the variables and function which are in the mainwindow...please check the below code if its not clear....

first dialog class
//header
class MainDialog;
class FirstDialog : public CDialog
{
    DECLARE_DYNAMIC(FirstDialog)
public:
    FirstDialog();//standard constr
    FirstDialog(MainDialog* pfirstPage);//constructor that i defined

protected:
    MainDialog* firstPage;
};
//cpp
intializing the constructor

FirstDialog::FirstDialog(MainDialog* pFirstPage)
    : CDialog(FirstDialog::IDD)
    ,firstPage(pFirstPage)
{

}

similarily  SecondDialog Class....
now i did the following

MainDialog main(L"Main Dialog");
    FirstDialog dialog1(&main);
    SecondPage   dialog2(&main);
    m_pMainWnd = &dialog1;
    INT_PTR nResponse = dialog1.DoModal();

so the problem is, Say if I have a CString variable in maindialog..I can call that variable and assign value in the first Dialog...but when I tried to access that value in the secondDialog..it restricts..there's no value..Please let me know if you are not able to understand..

+1  A: 

A potential issue is to have 2 different instances of this main dialog, but it does not look to be the case.

Is it possible that some other code overwrites the string value set by the first dialog ? Could you make the string not public and add a getter and a setter, so that you can easily have a breakpoint on the change of this field ? This way, you'll see what code accesses it.

Timores
I am not worried about that right now...I want to know how can I commmunicate between 2 dialogs with above code or with some other method...I beleive get/set method would not work...I am keep on working..but nothing seems to work..if u would help me that would be great..
kiddo
This is not really your original question, but anyway the recommended way to communicate is through an interface. Define one for the first dialog, with the necessary methods that the 2nd dialog needs and one for the communication with the second dialog. Then, change your constructors so that they receive an implementation of the needed interface. This'll make them communicate in a safe way.
Timores