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.
CDialog CPassInfoDlg(IDD_PASSINFO);
constructs a plainCDialog
object with nameCPassInfoDlg
. It does not create aCPassInfoDlg
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. – IInspectableCDialog CPassInfoDlg(IDD_PASSINFO);
uses the dialog resource identified throughIDD_PASSINFO
to construct the dialog, so the visuals look like the dialog you wanted. However, that dialog is not attached to aCPassInfoDlg
object, so your callbacks are never hit. In other words: The visuals are what the dialog resource defines. The behavior is that of a standardCDialog
object. – IInspectable