Link to home
Start Free TrialLog in
Avatar of puranik_p
puranik_pFlag for India

asked on

Passing window structure as a parameter.

I need to pass the info (variable) from one dialog class to another dialog class.

Can I do it by making use of dialog structure? If yes, how?
If not, How do I do it?
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Do you mean you have to open a second dialog from first dialog?
If so, you can create a pointer data member in second dialog to point data in first dialog,
then, you can implement SetData(somestruct *ptr) function in second dialog, so first dialog can do something like this:

CFirstDialog::OnSomeButtonFunction()
{
         CSecondDialog dlg;
         dlg.SetData(&yourStruct);
         dlg.DoModal();
}
ASKER CERTIFIED SOLUTION
Avatar of NawalKishore1976
NawalKishore1976

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NawalKishore1976
NawalKishore1976

or you can directly pass one by one car:

CFirstDialog::OnSomeButtonFunction()
{
         CSecondDialog dlg;

         dlg.m_v1=m_v1;

         dlg.m_v2=m_v2;

         dlg.DoModal();
}
One of the ways to do this is to make the structure or data that you want to pass to the dialog box, I assume it is to confire the dialog box, though the constructor.  This will only work for data.  If you wish to fill the dialog box's elements with something you will have to wait until after those elements have been created.  One of the functions , OnInitDialog, can be used for the Dialog to configure it's self.  If how ever you wish to have the parent configure the child you will need to create and interface for the parent to communicate with the child.  This is done through 'public' member functions.  Do not know how many elements you have but some times this can be extensive.  When the DoModal is called for the Dlg then you can use the public member functions to configure the Dialog.

HTH's
Gregg
Avatar of puranik_p

ASKER

How can I create a pointer data member in second dialog to point data in first dialog?
The same as my example

CFirstDialog::OnSomeButtonFunction()
{
         CSecondDialog dlg;
         dlg.SetData(this);           // <------ pointer to first dialog
         dlg.DoModal();
}

So you have to make some arrangements in second dialog declaration

SecondDialog.h

class CFirstDialog;   // Advance class declaration

class CSecondDlg : public CDialog  {
    CFirstDialog *m_pFirst;
    void SetData(CFirstDialog *data)  { m_pFirst = data }

   // The rest of dialog declaration
}

Now you can use m_pFirst pointer to access any data in first dialog (After setting pointer with SetData(), of course)
In Second Dialog Box

use the header file of the first dlg.



class CSecondDlg : public CDialog  {
    CDialog *m_pParentDlg;
    void SetParentDlg(CDialog *pDlg);


}


in first dlg

Call SetParentDlg(pDlg)

In SecongDlg.cpp

#include the header file of the FirstDlg.H

before using type cast it:

CFirstDlg * FirstDlg= (CFirstDlg*) m_pParentDlg;


use
FirstDlg->members





NawalKishore1976,
Besides the names you have used, I don't see difference between my answer and yours.
Yes the option is similar but there are some differences:
I am using the polymorphism, so that you can set any dialog box and there wont be any compilation problem also, without using the reference of
classFirstDlg