puranik_p
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?
Can I do it by making use of dialog structure? If yes, how?
If not, How do I do it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or you can directly pass one by one car:
CFirstDialog::OnSomeButton Function()
{
CSecondDialog dlg;
dlg.m_v1=m_v1;
dlg.m_v2=m_v2;
dlg.DoModal();
}
CFirstDialog::OnSomeButton
{
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
HTH's
Gregg
ASKER
How can I create a pointer data member in second dialog to point data in first dialog?
The same as my example
CFirstDialog::OnSomeButton Function()
{
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)
CFirstDialog::OnSomeButton
{
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
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.
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
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
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::OnSomeButton
{
CSecondDialog dlg;
dlg.SetData(&yourStruct);
dlg.DoModal();
}