Solved

struct's continued

Posted on 2000-02-15
4
260 Views
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
{
public:
    struct _myStruct
    {
      int test;
    }myStruct;
....
};

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!!!

0
Comment
Question by:rose337
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 2522223
Here:

>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.....
0
 
LVL 1

Accepted Solution

by:
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;
} MYSTRUCT;


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.

ie.

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

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

i.e.

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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2522255
ScottyDawg,

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.
0
 
LVL 1

Expert Comment

by:ScottyDawg
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).
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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…
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.

707 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

11 Experts available now in Live!

Get 1:1 Help Now