Solved

Passing variables to dialogs

Posted on 1998-12-21
6
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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