0
votes

Using VC6 and created a MFC dialog using the MFC AppWizard (exe). Inserted a second dialog and added the following to the original dialog:

#include "PassInfoDlg.h"

and in a function added:

CDialog CPassInfoDlg(IDD_PASSINFO);

INT_PTR nRet = -1;
TRACE("Before CPassInfoDlg.DoModal\n"); 
nRet = CPassInfoDlg.DoModal();
TRACE("CPassInfoDlg.DoModal = %d\n", nRet); 

PassInfoDlg has three buttons, OK, Cancel and Delete where Delete is set to IDC_DELETE. nRet = 1 or 2 when OK/Cancel pressed but the respective overrides do not occur. Further, the delete message function is never called. The trace only shows:

Before CPassInfoDlg.DoModal
CPassInfoDlg.DoModal = 1

even though there are additional traces in the second dialog. The second dialog consists of:

// PassInfoDlg.h

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

// Dialog Data
    //{{AFX_DATA(CPassInfoDlg)
    enum { IDD = IDD_PASSINFO };
    // NOTE: the ClassWizard will add data members here
//}}AFX_DATA

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CPassInfoDlg)
    public:
    virtual int DoModal();
    //}}AFX_VIRTUAL

// Implementation
protected:

    // Generated message map functions
    //{{AFX_MSG(CPassInfoDlg)
    virtual void OnOK();
    virtual void OnCancel();
    afx_msg void OnDelete();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};


// PassInfoDlg.cpp

CPassInfoDlg::CPassInfoDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CPassInfoDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CPassInfoDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}

BEGIN_MESSAGE_MAP(CPassInfoDlg, CDialog)
    //{{AFX_MSG_MAP(CPassInfoDlg)
    ON_BN_CLICKED(IDC_DELETE, OnDelete)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CPassInfoDlg message handlers

int CPassInfoDlg::DoModal() 
{
    TRACE("CPassInfoDlg::DoModal\n"); 
    return CDialog::DoModal();
}

void CPassInfoDlg::OnOK() 
{
    TRACE("CPassInfoDlg::OnOK\n"); 
    CDialog::OnOK();
}

void CPassInfoDlg::OnCancel() 
{
    TRACE("CPassInfoDlg::OnCancel\n"); 
    CDialog::OnCancel();
}

void CPassInfoDlg::OnDelete() 
{
    TRACE("CPassInfoDlg::OnDelete\n"); 
    EndDialog(IDC_DELETE);
}

None of the overrides or the Delete message are called. I can tab between the three buttons and clicking or pressing on the OK or Cancel works, neglecting the overrides are not called. No response when pressing the Delete button. It seems straight forward with the MFC wizard, but I'm not sure what I'm doing wrong.

1
CDialog CPassInfoDlg(IDD_PASSINFO); constructs a plain CDialog object with name CPassInfoDlg. It does not create a CPassInfoDlg object.A somewhat recent compiler probably would have warned about this. 2017 looks like a good year to drop a 19-year-old compiler/IDE.IInspectable
I agree about upgrading, but then there's a good chance I'll need to replace the hardware and OS as well. Bigger project than I currently want to commit to. I had seen the method that I used on a MSDN site, so that's how I went off going in that direction. The fact that it successfully launched the second dialog gave me the impression I was going in the right direction.Codybear
CDialog CPassInfoDlg(IDD_PASSINFO); uses the dialog resource identified through IDD_PASSINFO to construct the dialog, so the visuals look like the dialog you wanted. However, that dialog is not attached to a CPassInfoDlg object, so your callbacks are never hit. In other words: The visuals are what the dialog resource defines. The behavior is that of a standard CDialog object.IInspectable

1 Answers

0
votes

Figures, spent hours on this before posting and after posting, I came up with my own answer. The following change to the original dialog appears to work:

    CPassInfoDlg dlg;

// Create and show the dialog box
    INT_PTR nRet = -1;
    TRACE("Before dlg.DoModal\n"); 
    nRet = dlg.DoModal();
    TRACE("dlg.DoModal = %d\n", nRet);

Now the DoModal override is being called as well as the others. Probably multiple ways to do this, but at least I'm good to go.