Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing variables to dialogs

Posted on 1998-12-21
6
Medium Priority
?
274 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 100 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
Independent Software Vendors: 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!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

885 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