Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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?
0
puranik_p
Asked:
puranik_p
1 Solution
 
Jaime OlivaresCommented:
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();
}
0
 
NawalKishore1976Commented:
Hi,

You can use the pointer of Dialog in the Child Dialog to retrive all the variables.
In SecongDlg create a Pointer Variable

CFirstDialog::OnSomeButtonFunction()
{
         CSecondDialog dlg;
         dlg.m_pParentDlg=this;
         dlg.DoModal();
}
0
 
NawalKishore1976Commented:
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();
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
graberCommented:
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
0
 
puranik_pAuthor Commented:
How can I create a pointer data member in second dialog to point data in first dialog?
0
 
Jaime OlivaresCommented:
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)
0
 
NawalKishore1976Commented:
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





0
 
Jaime OlivaresCommented:
NawalKishore1976,
Besides the names you have used, I don't see difference between my answer and yours.
0
 
NawalKishore1976Commented:
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now