Solved

Passing variables to dialogs

Posted on 1998-12-21
6
264 Views
Last Modified: 2010-04-02
I am using VC++ 5.0 and have written a program in Dialog mode. I have a Main Dialog and several other dialogs that open when I click a button.

I know how to pass variables from the other Dialogs to the Main Dialog by using this:

m_dlg.m_Variable

Since m_dlg is the reference it uses to refer to the Dialog and m_Variable is the variable name, how do I pass a variable from the Main Dialog to the other Dialogs?

Thanks
Randy
0
Comment
Question by:randyg
6 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1180779
When you declare the 2nd, 3rd, 4th dialog you must have

Either
(a) Defined a scratch variable
CSecondDlg dlg2 ;
dlg2.DoModal() ;

In this case insert code between these 2 lines
CSecondDlg dlg2 ;
dlg2.m_value = 5 ;
dlg2.DoModal() ;

or

(b) Added the second dialog as a class member of the first, e.g. m_dlg2 is a member of CFirstDlg

Then you can do
m_dlg2.m_variable = 99 ; // or whatever

0
 

Author Comment

by:randyg
ID: 1180780
Thanks for the answer, but I don't think that I did a very good job explaining the question.

I have a Main Dialog and three other Dialogs that open everytime I click on three buttons.
In the CFilenameDlg.h I added this to declare the each of the three dialogs:

class CMy3170_serial_portDlg : public CDialog
{
// Construction
public:
      CMy3170_serial_portDlg(CWnd* pParent = NULL);      // standard constructor

      CFirstDlg m_dlg0;         // I added this
      CSecondDlg m_dlg1;    // I added this
      CThirdDlg m_dlg2;        // I added this

So now when ever I am in the Main Dialog and want to pass a variable from either one of these Dialogs I use this :

m_dlg0.m_Variable=0;

But the problem I am having is when I'm in one of the three Dialogs and I want to get a Variable from the Main Dialog I can't seem to do this since I didn't declare the Main Dialog as anything. Where do I declare it? How do I declare it? How do I call it into the other Dialogs?

Thanks
Randy
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1180781
That would be my question as well,  is this your question?

MAINDIALOG: ----> 3 others.

you can't get MAINDIALOG variables when in the 3 others;

BUT you can get 3 others variable when in MAINDIALOG;

My question is the same, exept I used Database and I have mainfrm.


0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Expert Comment

by:mmachie
ID: 1180782
you could something like this:
CFirstDlg ::set_parent( CMy3170_serial_portDlg *Parent) {
   m_pparent = Parent;
   m_cfirstdlg_variable = m_pparent.m_maindlg_varialbe;
}
you need some way to reference CMy3170_serial_portDlg  in your dialog classes.  the above is one way and there are many others, i believe this will be the least painful.

hth,
mikem
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1180783
I work around this problem in this way.
Include the maindialog.h file in each of the child dialog classes.
wherever you want to access the maindialog's variables, you can do this:
      CMainDialog *mdlg=(CMainDialog *)GetParent();
      mdlg->variablename=myvalue;
thanks. hope this helps.
merry christmas to you all.
pagladasu
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1180784
Merry Christmas to you guys as well.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question