CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    1

    How to create nested dialog boxes in MFC?

    Hi all,

    I'm a complete beginner to using MFC. I am currently creating simple applications, and trying to improve my knowledge.

    I'm having a problem with creating usable buttons within child dialog boxes of the main dialog. The button in the second dialog box should link to a 3rd dialog box when it is clicked...but it doesn't work. Can anyone tell me what I'm doing wrong?

    #include <afxwin.h>
    #include <afxdlgs.h>
    #include "resource1.h"

    class CWindowApp : public CWinApp
    {
    public:
    BOOL InitInstance();
    };

    class CWindowDlg : public CDialog
    {
    public:
    enum { IDD = IDD_DIALOG1 };

    CWindowDlg();
    ~CWindowDlg();
    DECLARE_MESSAGE_MAP()
    afx_msg void OnBnClickedButton1();
    };

    CWindowDlg::CWindowDlg() : CDialog(CWindowDlg::IDD)
    {
    }

    CWindowDlg::~CWindowDlg()
    {
    }


    class CWindowDlg2 : public CDialog
    {
    public:
    enum { IDD = IDD_DIALOG2 };

    CWindowDlg2();
    ~CWindowDlg2();
    DECLARE_MESSAGE_MAP()
    afx_msg void OnBnClickedButton2();
    };

    CWindowDlg2::CWindowDlg2() : CDialog(CWindowDlg2::IDD)
    {
    }

    CWindowDlg2::~CWindowDlg2()
    {
    }

    class CWindowDlg3 : public CDialog
    {
    public:
    enum { IDD = IDD_DIALOG3 };

    CWindowDlg3();
    ~CWindowDlg3();
    };

    CWindowDlg3::CWindowDlg3() : CDialog(CWindowDlg3::IDD)
    {
    }

    CWindowDlg3::~CWindowDlg3()
    {
    }


    BOOL CWindowApp::InitInstance()
    {
    CWindowDlg Dlg;

    m_pMainWnd = &Dlg;
    Dlg.DoModal();

    return TRUE;
    }

    CWindowApp theApp;

    BEGIN_MESSAGE_MAP(CWindowDlg, CDialog)
    ON_BN_CLICKED(IDC_BUTTON1, &CWindowDlg::OnBnClickedButton1)
    END_MESSAGE_MAP()

    void CWindowDlg::OnBnClickedButton1()
    {
    // TODO: Add your control notification handler code here
    CDialog dlg(IDD_DIALOG2);
    dlg.DoModal();
    }
    BEGIN_MESSAGE_MAP(CWindowDlg2, CDialog)
    ON_BN_CLICKED(IDC_BUTTON2, &CWindowDlg2::OnBnClickedButton2)
    END_MESSAGE_MAP()

    void CWindowDlg2::OnBnClickedButton2()
    {
    // TODO: Add your control notification handler code here
    CDialog dlg2(IDD_DIALOG3);
    dlg2.DoModal();
    }

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to create nested dialog boxes in MFC?

    If you use code tags [code][/code] instead of quote the code indentation is preserved.

    The first you always should do is to check how the function you use informs you in case of a failure. For DoModal GetLastError returns the reason for the failure. See http://msdn.microsoft.com/en-us/library/619z63f5.aspx
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured