Saving Child Dialog settings

I have a SDI CFormView (Doc/View Arch support) which has 4 buttons that when ever 1 of the buttons is clicked, a child Modal dialog box (popup) with check box controls and radio buttons is displayed.  I want to be able to add to the File Menu a "Save Configuration", "Load Configuration", and "Load Default Configuration.  

How would I save my current configuration which would save the state of each control in the child dialog boxes?   How would I go about loading it back again after it is saved.  How would I Load a Default configuration.  Would the serialze function work for this? Would I have to create another class to keep track of the current selection and serialize that information when the "Save Configuration is called"?
uriveraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Configuration settings are kept in the Registry. See CWinApp::WriteProfileString and CWinApp::GetProfileString functions.
Suppose you have set of variables which describe current program state. To save this set to the Registry, write each of these variables using WriteProfileString. To restore them from the Registry, read them using GetProfileString and set dialog controls accordingly.
Load Default Configuration - set these variables to hard-coded default values and update dialog controls.
Don't forget to set unique Registry key in SetRegistryKey call in InitInstance.
0
uriveraAuthor Commented:
Thank You AlexFM for your comment.  

When using the WriteProfileString does that allow you save multiple configurations? For example, the user might want to save multiple configurations and name them like a file say myConfiguration.cof; yesterdaysConf.cof;  so when he does a "Load Configuration" he can choose which one he wants to load.  The same way when opening up a text file in notepad you first save the file then when you go open a file you can select from many files.
0
AlexFMCommented:
Registry allows to keep any information, it's up to you to provide application logic. CWinApp Registry functions allow to keep settings in two levels. You select application key name by SetRegistryKey call. Under this key you can create any number of sections, every section keeps number of entries. You decide what entries and sections you have.
For example, you can have section "Configurations", which has entry Number (number of configurations). Every configuration has it's own section with name and user-specific values.

Application key
    Configurations
           Number            2
    Configuration1
           Name               myConfiguration
           Selection          1
           Color                Red
           ...
    Configuration2
           Name               yesterdaysConf
           Selection          2
           Color               Green
           ...

You can implement all this logic using CWinApp::WriteProfileString and CWinApp::GetProfileString functions.
Selection and Color are samples of configuration variables.

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

uriveraAuthor Commented:
Thanks AlexFM.  Do you know of any code examples out there that do this?  
0
AlexFMCommented:
Let's say that we have array of preference structures:

struct PREFERENCE
{
    CString name;    // configuration name
    int nData1;      // some data
    int nData2;
};

REFERENCE* m_refarray;
int m_nRef;   // number of members filled in array

The following functions may be used to save/load this array to/from Registry. I assume that this code is executed in aplication class. If not, add AfxGetApp()-> to every call of Registry function.

#define GENERAL_SECTION "Configurations"
#define CONFIGURATION_SECTION "Configuration"
#define NUMBER_ENTRY "Number"
#define NAME_ENTRY "Name"
#define DATA1_ENTRY "Data1"
#define DATA2_ENTRY "Data2"


Save to registry. Input: m_refarray, m_nRef

WriteProfileInt(GENERAL_SECTION, NUMBER_ENTRY, m_nRef);

for ( int i = 0; i < m_nRef; i++ )
{
    CString s;   // section name
    s.Format("%s%d", CONFIGURATION_SECTION, i);    // Section name: Configuration0, Configuration1...

    WriteProfileString(s, NAME_ENTRY, m_refarray[i].name);
    WriteProfileString(s, DATA1_ENTRY, m_refarray[i].nData1);
    WriteProfileString(s, DATA2_ENTRY, m_refarray[i].nData2);
}


Load from registry. Output: m_refarray, m_nRef

m_nRef = GetProfileInt(GENERAL_SECTION, NUMBER_ENTRY, 0);   // 0 is default value

if ( m_nRef == 0 )
    return;

m_refarray = new PREFERENCE[m_nRef];

for ( int i = 0; i < m_nRef; i++ )
{
    CString s;   // section name
    s.Format("%s%d", CONFIGURATION_SECTION, i);

    m_refarray[i].name = GetProfileString(s, NAME_ENTRY,"Unknown");
    m_refarray[i].nData1 = GetProfileString(s, DATA1_ENTRY, 0);
    m_refarray[i].nData2 = GetProfileString(s, DATA2_ENTRY, 0);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
uriveraAuthor Commented:
For the default configuration, does the code that creates the entry on the registry get created on the InitInstance or some method that get invoked right when the application is launched? Or does it get created through the install program (install shield or something like that) and then just loaded using the GetProfileInit and GetProfileString methods?
Also, is there a way of knowing if specific configuration name has been saved without having to go through all of the ones saved to check?
0
uriveraAuthor Commented:
I want the default configuration to be loaded automatically everytime the application is loaded.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.