Solved

struct's continued

Posted on 2000-02-15
4
262 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 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