Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

struct's continued

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
rose337
Asked:
rose337
  • 2
  • 2
1 Solution
 
jhanceCommented:
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
 
ScottyDawgCommented:
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
 
jhanceCommented:
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
 
ScottyDawgCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now