Working with Child Dialog boxes

I have a few questions, that is why I'm making this question worth 350 points.

I am writing a FormView application (with Doc/View support) on the Form(lets call this the parent) I have buttons that when clicked launch a modeless dialog box (lets call this the child dialog box), in that box I have radio buttons and check boxes.

1)  I need to know how to default a radio button and check box in the child dialog boxes to be selected when the parent dialog (Form) is launched.  For example, user starts the application, then clicks on button1 that displays child dialog box with certain default settings.

2) How do I program it so that if the user launches a child dialog box, changes the state of the radio buttons or check boxes clicks OK, returns the the parent Form, then launches the same child dialog box and it displays the last settings the user selected NOT the default settings.

3) How do I get the information of the settings of the radio butttons and check boxes from each child dialog box back to the parent form, so I can display the current settings on some static string or edit string.  Is there an efficient and elegant way of doing it in MFC?


I tried using the OnInitDialog function on the parent form to set the default settings for the child dialogs but that did not work.  If i do it from the OnInitDialog function of the child dialog would that not keep that last setting done by the user, wouldn't it revert back to the default setting everytime the user launched the child dialog?  

I want to avoid using the GetDlgItem() function, I want to avoid using it as much as possible in MFC.
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.

AndyAinscowFreelance programmer / ConsultantCommented:
Possibly the simplest way is to have variables linked to the controls (class wizard, add variable tab).
1) when you create/display the dialog you have code like the following
m_pDlg->m_iRadio = 2;
m_pDlg->UpdateData(false);
This will set the third radio button (zero based counting).
2) Modeless dialog boxs you need to handle the OK and CANCEL events yourself.  If you just hide the dialog then when you reshow it (next time button is pressed) the previous settings are there.
3)  The opposite to 1)
m_pDlg->UpdateData(true);
m_pDlg->m_iRadio contains which radio is selected.
0
AlexFMCommented:
You need to keep child dialog settings in some place in the parent form, which is available to the child dialog, when it is initialized. This may be, for example, structure which is kept in the parent form. Pointer to this structure is passed to the child dialog. Child dialog fills it's controls according to this structure. When child dialog is closed, it fills this structure with current selection.

// CurrentChoice.h
#pragma once

struct CURRENT_CHOICE
{
    int nRadioSelection;
    // ... other information
};

// ParentForm.h
#include "CurrentChoice.h"

class CParentForm
{
    ...
    CURRENT_CHOICE m_Choice;
   ...
}

// ParentForm.cpp

ParentForm()
{
    m_Choice.nRadioSelection = 0;   // initial choice
    // ...
}

void CParentForm::OnShowDialog()
{
    // Show dialog here
    // Set it's m_pChoice member:
    pDlg->m_pChoice = &m_Choice;   // before Create !
}

// ChildDialog.h
#include "CurrentChoice.h"

class CChildDialog
{
    ...
    CURRENT_CHOICE* m_pChoice;
}

// ChildDialog.cpp

BOOL CChildDialog::OnInitDialog()
{
    // set here dialog controls according to m_pChoice members
    // ...
}

void CChildDialog::OnOK()
{
    // fill here m_pChoice members according to current state of dialog controls
}
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:
Andy I don't quite understand your solution.

Alex, does the child Dlg have access to a pointer to the parent Dlg? Or how does the pointer get passed.

0
AlexFMCommented:
void CParentForm::OnShowDialog()
{
    // Show dialog here
    // Set it's m_pChoice member:
    pDlg->m_pChoice = &m_Choice;
    pDlg->Create(...);
   
}
0
AndyAinscowFreelance programmer / ConsultantCommented:
What don't you understand?  The only obvious thing further I can say is that m_pDlg is a pointer to the modeless dialog you have just created.
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.