Go Premium for a chance to win a PS4. Enter to Win

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

nested Dialogs

I need a full example to handle nested Dialogs.

The Dialog has a List box control. Depending on the List box selection a child dialog should be displayed.
0
Gus012498
Asked:
Gus012498
  • 3
1 Solution
 
petern012698Commented:
Gus,
I can knock-up a sample for you, how many types of dialogs would you like.  Is it context-sensitive from the list box or is the same dialog for each one.  Do you want the dialog to be shown on double-click.
Send me an eMail and I will create it for you overnight.

0
 
Gus012498Author Commented:
The program is a little bit more complex.

I have a main application which loads several DLL. Each DLL register a Document Template or a Connection Template.

The Dialog is used to setup the Connections.
The Listbox contains the names of the Templates.

When a listbox item is selected and the Create Button is pressed a new Connection is created an a part of the main Dialog should display the Connectionsparameters. (Portnumber and Baudrate for RS232, Device ID for CAN, ...).

If your example shows me how to display one nested dialog, i should be able to do the rest.
0
 
petern012698Commented:
Gus,
Unfortunatly not all of your answer was visible, can you email me at peter.nunn@purist.com with the details, so I can get onto it
0
 
petern012698Commented:
Gus, I think I understood but you havn't responded to my eMail.  Here are 2 cpp files that implement an outer dialog with a list-box (CTemplateDlg) and a nested dialog (CConfigurationDlg) when a valid list-box item is selected the outer dialog is shown.
I can send the whole sample by eMail when you send it
--------------------------------------
#if !defined(AFX_TEMPLATEDLG_H__E8B62956_9626_11D1_9C84_004005325433__INCLUDED_)
#define AFX_TEMPLATEDLG_H__E8B62956_9626_11D1_9C84_004005325433__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// TemplateDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CTemplateDlg dialog

class CTemplateDlg : public CDialog
{
// Construction
public:
      CTemplateDlg(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
      //{{AFX_DATA(CTemplateDlg)
      enum { IDD = IDD_TEMPLATES };
      CListBox      m_wndTemplateName;
      CString      m_strTemplateName;
      //}}AFX_DATA


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CTemplateDlg)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:

      // Generated message map functions
      //{{AFX_MSG(CTemplateDlg)
      afx_msg void OnConfiguration();
      virtual BOOL OnInitDialog();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TEMPLATEDLG_H__E8B62956_9626_11D1_9C84_004005325433__INCLUDED_)
---------------------------------------
// TemplateDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Nested.h"
#include "TemplateDlg.h"

#include "configurationdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTemplateDlg dialog


CTemplateDlg::CTemplateDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CTemplateDlg::IDD, pParent)
{
      //{{AFX_DATA_INIT(CTemplateDlg)
      m_strTemplateName = _T("");
      //}}AFX_DATA_INIT
}


void CTemplateDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CTemplateDlg)
      DDX_Control(pDX, IDC_TEMPLATE_NAME, m_wndTemplateName);
      DDX_LBString(pDX, IDC_TEMPLATE_NAME, m_strTemplateName);
      //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTemplateDlg, CDialog)
      //{{AFX_MSG_MAP(CTemplateDlg)
      ON_BN_CLICKED(IDC_CONFIGURATION, OnConfiguration)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTemplateDlg message handlers

void CTemplateDlg::OnConfiguration()
      {
      // TODO: Add your control notification handler code here
      if(m_wndTemplateName.GetCurSel() == LB_ERR)
            {
            AfxMessageBox(_T("Please select a template name"));
            return;
            }

      CConfigurationDlg dlg;

      // this reads the contents of the variables
      UpdateData();

      // copy it accross
      dlg.m_strTemplateName = m_strTemplateName;
      dlg.DoModal();
      }

BOOL CTemplateDlg::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here

      // we add some dummy names here
      m_wndTemplateName.AddString(_T("Template 1"));
      m_wndTemplateName.AddString(_T("Template 2"));
      m_wndTemplateName.AddString(_T("Template 3"));
      m_wndTemplateName.AddString(_T("Template 4"));
      m_wndTemplateName.AddString(_T("Template 5"));
      m_wndTemplateName.AddString(_T("Template 6"));
      m_wndTemplateName.AddString(_T("Template 7"));
      m_wndTemplateName.AddString(_T("Template 8"));
      
      return TRUE;  // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
}
------------------------------
#if !defined(AFX_CONFIGURATIONDLG_H__E8B62957_9626_11D1_9C84_004005325433__INCLUDED_)
#define AFX_CONFIGURATIONDLG_H__E8B62957_9626_11D1_9C84_004005325433__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ConfigurationDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CConfigurationDlg dialog

class CConfigurationDlg : public CDialog
{
// Construction
public:
      CConfigurationDlg(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
      //{{AFX_DATA(CConfigurationDlg)
      enum { IDD = IDD_CONFIGURATION };
      BOOL      m_bParam1;
      CString      m_strTemplateName;
      //}}AFX_DATA


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CConfigurationDlg)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:

      // Generated message map functions
      //{{AFX_MSG(CConfigurationDlg)
      virtual BOOL OnInitDialog();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CONFIGURATIONDLG_H__E8B62957_9626_11D1_9C84_004005325433__INCLUDED_)
------------------------------------------
// ConfigurationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Nested.h"
#include "ConfigurationDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConfigurationDlg dialog


CConfigurationDlg::CConfigurationDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CConfigurationDlg::IDD, pParent)
{
      //{{AFX_DATA_INIT(CConfigurationDlg)
      m_bParam1 = FALSE;
      m_strTemplateName = _T("");
      //}}AFX_DATA_INIT
}


void CConfigurationDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CConfigurationDlg)
      DDX_Check(pDX, IDC_PARAM1, m_bParam1);
      DDX_Text(pDX, IDC_TEMPLATE_NAME, m_strTemplateName);
      //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigurationDlg, CDialog)
      //{{AFX_MSG_MAP(CConfigurationDlg)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigurationDlg message handlers

BOOL CConfigurationDlg::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here

      // rather simple demo of changing the param
      m_bParam1 = m_strTemplateName == _T("Template 2");

      // this sets the controls from the parameters
      UpdateData(FALSE);
      
      return TRUE;  // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
}
-----------------------------------
Hope it helps
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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