Solved

Passing variables to dialogs

Posted on 1998-12-21
6
261 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Implementing a ResolveEventHandler in C++ 13 114
Fully specialized class template function 21 129
How to copy an image file into clipboard C/C++? 1 151
max float value 3 21
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now