Solved

struct's

Posted on 2000-02-14
1
288 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
1 Comment
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 70 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

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

759 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

16 Experts available now in Live!

Get 1:1 Help Now