?
Solved

struct's

Posted on 2000-02-14
1
Medium Priority
?
296 Views
Last Modified: 2010-04-02
Hi, I have a dialog based MFC app with 4 property pages. I have twenty variables to pass between the property pages and my dialog box. What is the best way of doing this? I assume that placing the variables into a structure is the best way, but now how do I use it and pass it between my dialog box class and the property pages classes? Added information is that the variables are initialised and used in the dialog box class, but the property pages are used to altered the variables. If possible, please show me through a simple example how to pass the struct around, assuming of course that the struct is the best way to do this. More added information is that I have been using global variables to start off with, and I want to move away from this to the struct, or whatever. Thanks.
0
Comment
Question by:rose337
[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
1 Comment
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 210 total points
ID: 2519079
The struct part is irrelevant for the time being.

Create your class derived from CPropertySheet and add to it all the member variables you wish to use – make sure they are declared as public:

Now each property page can look at its parent for the member variables. E.g.

Void Foo(int a, int b, in c)
{
      // Create the pages
      Cpage1 Page1;
      Cpage2 Page2;

      // Create the property sheet
      CmyPropertySheet MySheet;

      // Add the pages to the propertysheet
      MySheet.AddPage(&Page1);
      MySheet.AddPage(&Page2);

      // Initialise the variables
MySheet.a = a;
MySheet.b = b;
MySheet.c = c;

MySheet.DoModal();
}


Cpage1::OnDoSomething()
{
      CMySheet* pMySheet = (CMySheet*)GetParent;
      ASSERT(pMySheet);

      // access member vars via pMySheet
      pMySheet->a = pMySheet.b + pMySheet.c;
}
0

Featured Post

Industry Leaders: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

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