Solved

Passing variables to dialogs

Posted on 1998-12-21
6
258 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Expert Comment

by:mmachie
Comment Utility
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
Comment Utility
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
Comment Utility
Merry Christmas to you guys as well.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

9 Experts available now in Live!

Get 1:1 Help Now