473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

MFC dialog class

I have five dialog classes in one project. Is it possible for the data from
I store in variable m_object from one class to be passed to another dialog
class.

The basic set-up of my project. When the user in dialog class ONE clicks
OK, it goes to dialog TWO. I have a getfunciton that retrieves the data
from the variable m_object. The problem is that when I call this function
in dialog TWO it passes whatever is in my constructor.
Nov 16 '05 #1
3 1193
meipv wrote:
I have five dialog classes in one project. Is it possible for the data from
I store in variable m_object from one class to be passed to another dialog
class.

The basic set-up of my project. When the user in dialog class ONE clicks
OK, it goes to dialog TWO. I have a getfunciton that retrieves the data
from the variable m_object. The problem is that when I call this function
in dialog TWO it passes whatever is in my constructor.


It sounds like dialog TWO's ctor should take a reference parameter, e.g.

DlgTWO(X& x)
: m_x(x)
{
}

Above, m_x is a member variable which has type X&, X being the type of
m_object. This makes m_x an alias for m_object. For this to work, the
lifetime of x must exceed DlgTWO's use of m_x.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 16 '05 #2
So, if m_object is a CString. X should also be of type CString? How do I
allow the lifetime of m_x to exceed x. Since m_object is from Dialog One is
there anything that I need to change in it or are all the changes made to
dialog TWO. Thanks so much for your help and replying.
Nov 16 '05 #3
meipv wrote:
So, if m_object is a CString. X should also be of type CString? How do I
allow the lifetime of m_x to exceed x. Since m_object is from Dialog One is
there anything that I need to change in it or are all the changes made to
dialog TWO. Thanks so much for your help and replying.


Assume you have two modal dialog classes, Dlg1 and Dlg2, and you have a Dlg1
button handler as below:

void Dlg1::OnCallDlg2()
{
// More on cs below.
Dlg2 dlg2(cs);
if (dlg2.DoModal() == IDOK)
whatever;
}

The Dlg2 class looks something like this:

class Dlg2
{
public:

Dlg2(CString& cs)
: m_cs(cs)
{
}

private:

CString& m_cs;
};

Member functions in Dlg2 can modify the CString passed into its ctor through
the m_cs reference. (If you don't understand this, read up on "references".)

In this Dlg1::OnCallDlg2 line:

Dlg2 dlg2(cs);

The CString cs can be a local variable declared before dlg2, e.g.

CString cs;
cs.LoadString(IDS_WHATEVER);
Dlg2 dlg2(cs);

Or it can be a member variable of Dlg1. The important thing is that it's not
destroyed while Dlg2 is still using it, because Dlg2's m_cs reference member
is just another way of referring to cs.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fred | last post by:
Hi, I'd like to turn a command-line script into a Windows GUI app using the native widgets so as to reduce the size of the binary (ie. no QT, wxWidgets, et al.) I came up with the following...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
3
by: CaribSoft | last post by:
I want to create my own common dialog to use in an application . How do I show a custom dialog (form) in a class based on the common dialog class?
4
by: Alexander | last post by:
Hi, I have written a program that takes on some operations much more time than I expected. As I have seen users clicking wildly on the screen to make something happen, I want to follow the...
3
by: Greg Horwood | last post by:
Dear Anyone, While most of you will laugh at the fundamental nature of my question, I am a bit stuck. I am a reasonable VC++ programmer trying to make the switch to C#. I am trying to create a...
6
by: bryanhobson | last post by:
I'm fairly new to c#, and I am just trying to work out how a 'properties' dialog works. Currently in my code, I have an object represented by the class 'Dog'. The dog object has several...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: drummond.ian | last post by:
Hello Everyone, This problem's been causing me a lot of trouble and I'm hoping somebody can help me out!! I have a dialog-based MFC application in visual studio 2003. I want to call a...
6
by: kdikert | last post by:
I have a worker thread, and when the worker is done I want it to show a popup dialog. The sample application below demonstrates this. There are two buttons: a "Show dialog" button which immediately...
1
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.