struct's continued

Posted on 2000-02-15
Last Modified: 2010-04-02
Hi, althought this is a new question, it does have its roots in my previous question. Now I have decided to define a struct (myStruct) as public in my dialog box class (CmyDlg). I have a button on the dialog box to open a property sheet with four property pages on it. I want to manipulate the data in the property sheet and return the altered struct back to my dialog box class. So far I have this struct...

class CMyDlg : public CDialog
    struct _myStruct
      int test;

I then added a button with this function...

myStruct.test = 1;
CMyPropertySheet propSheet;
int propSheetReturn = propSheet.DoModal();
int j = myStruct.test;

which obviously sets the data in the structure, opens the property sheet, and when the sheet is closed, I check my data to see if it has changed. And I want it to have changed. I want a function in the property page to change the test variable to 2. So the dialog box with its own class opens the property sheet with its own class which opens up the four pages each with their own class. A function I call in CPropertyPage1 must change the variable to 2.

Well I hope that I explained that clearly. I have tried everything and it all runs but does not pass the data along... help!!!

Question by:rose337
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
  • 2
  • 2
LVL 32

Expert Comment

ID: 2522223

>CMyPropertySheet propSheet;
>int propSheetReturn = propSheet.DoModal();

you are creating a new class that knows nothing of your struct.  How are you passing this information to propSheet?  You've left out some important details.....

Accepted Solution

ScottyDawg earned 70 total points
ID: 2522238
Okay Rose, you're almost there however, just a couple of things to sort out.

First of all make a typedef of your struct that will be available to both your dialog and your property sheet i.e.

typedef struct
int test;

now decalare two variables of type MYSTRUCT in the dialog class and the propertysheet class.

i.e. MYSTRUCT myStruct;

Now when you create the propertysheet copy the dialog myStruct to the propertysheet mystruct.


myStruct.test = 1;
CMyPropertySheet propSheet;
propSheet.myStruct = myStruct

after you call DoModal on the propertysheet you can copy the data back to the dialog:


if (propSheet.DoModal() != IDOK)
return; // don't update

myStruct = propSheet.myStruct.


Hope that helps. Remember, that if you add other elements to your struct such as a char*, you won't actually copy the string, just the pointer. So in this case a straight assignment may not be what you want, but rather a memcpy.
LVL 32

Expert Comment

ID: 2522255

Thanks for stepping all over my comment with your answer! I hope to repay the favor someday soon.....  

But then looking at your EE profile, I see that you _DO_ need the points.

Expert Comment

ID: 2522264
jHance, I'd answered Rose's previous question so had an idea about what she wanted. Also, when I first loaded the page, you're comment hadn't even been posted (check times). If you feel you need the points take them (seeing as I've no idea what they do anyhow).

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
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. …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

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