开发者

Not able to communicate between dialogs by passing their object as Reference!

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 wi开发者_运维知识库ndow 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..


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜