?
Solved

Working with Child Dialog boxes

Posted on 2004-11-18
5
Medium Priority
?
301 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:urivera
  • 2
  • 2
5 Comments
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 150 total points
ID: 12612501
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 900 total points
ID: 12612551
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
 

Author Comment

by:urivera
ID: 12628995
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 12629028
void CParentForm::OnShowDialog()
{
    // Show dialog here
    // Set it's m_pChoice member:
    pDlg->m_pChoice = &m_Choice;
    pDlg->Create(...);
   
}
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12629930
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 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