头文件: #if !defined(AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_) #define AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_#include "DlgMasterInfo.h" // Added by ClassView #include "DlgSiteSelect.h" // Added by ClassView #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // DlgSend.h : header file /////////////////////////////////////////////////////////////////////////////// // CDlgSend dialogclass CDlgSend : public CDialog { // Construction public: CDlgSiteSelect m_DlgSiteSelect; CDlgMasterInfo m_DlgMasterInfo; CDlgSend(CWnd* pParent = NULL); // standard constructor// Dialog Data //{{AFX_DATA(CDlgSend) enum { IDD = IDD_SEND }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CDlgSend) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementation protected: // Generated message map functions //{{AFX_MSG(CDlgSend) afx_msg void OnBtnRevise(); virtual BOOL OnInitDialog(); afx_msg void OnRbtnSelfselect(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };//{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_)
源文件: // DlgSend.cpp : implementation file //#include "stdafx.h" #include "InfoSender.h" #include "DlgSend.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CDlgSend dialog CDlgSend::CDlgSend(CWnd* pParent /*=NULL*/) : CDialog(CDlgSend::IDD, pParent) { //{{AFX_DATA_INIT(CDlgSend) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CDlgSend::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgSend) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDlgSend, CDialog) //{{AFX_MSG_MAP(CDlgSend) ON_BN_CLICKED(IDC_BTN_REVISE, OnBtnRevise) ON_BN_CLICKED(IDC_RBTN_SELFSELECT, OnRbtnSelfselect) //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CDlgSend message handlers BOOL CDlgSend::OnInitDialog() { CDialog::OnInitDialog();
// TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }void CDlgSend::OnBtnRevise() { // TODO: Add your control notification handler code here m_DlgMasterInfo.DoModal(); }void CDlgSend::OnRbtnSelfselect() { // TODO: Add your control notification handler code here m_DlgSiteSelect.DoModal(); MessageBox("Love!"); }
之前我还有另外一个类,后来删掉了这个类,重建了.clw文件,但是编译链接的时候还是老警告美找到那个被删掉的类文件。刚才从工程中搜索,发现在.dsp中有: SOURCE=.\DlgXXX.cpp # End Source File # Begin Source File SOURCE=.\DlgXXX.cpp # Begin Source File # End Source File 这样的文件,删掉,保存,然后再编译程序就没有问题了,这是为什么呢?
我把程序这样改了一下,但是想让弹出的模式对话框在关闭的时候同时释放指向该对象的指针,不知道怎么弄// DlgSend.cpp : implementation file //#include "stdafx.h" #include "InfoSender.h" #include "DlgSend.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CDlgSend dialog CDlgSend::CDlgSend(CWnd* pParent /*=NULL*/) : CDialog(CDlgSend::IDD, pParent) { //{{AFX_DATA_INIT(CDlgSend) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT }CDlgSend::~CDlgSend() { delete pDlgMasterInfo; delete pDlgSiteSelect; } void CDlgSend::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgSend) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDlgSend, CDialog) //{{AFX_MSG_MAP(CDlgSend) ON_BN_CLICKED(IDC_BTN_REVISE, OnBtnRevise) ON_BN_CLICKED(IDC_RBTN_SELFSELECT, OnRbtnSelfselect) //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CDlgSend message handlers BOOL CDlgSend::OnInitDialog() { CDialog::OnInitDialog();
// TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }void CDlgSend::OnBtnRevise() { // TODO: Add your control notification handler code here pDlgMasterInfo = (CDlgMasterInfo *)new CDlgMasterInfo; pDlgMasterInfo->DoModal(); }void CDlgSend::OnRbtnSelfselect() { // TODO: Add your control notification handler code here pDlgSiteSelect = (CDlgSiteSelect *)new CDlgSiteSelect; pDlgSiteSelect->DoModal(); }
应该是简单错误。在DEBUG模式下调试很容易定位断点。
#if !defined(AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_)
#define AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_#include "DlgMasterInfo.h" // Added by ClassView
#include "DlgSiteSelect.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgSend.h : header file
///////////////////////////////////////////////////////////////////////////////
// CDlgSend dialogclass CDlgSend : public CDialog
{
// Construction
public:
CDlgSiteSelect m_DlgSiteSelect;
CDlgMasterInfo m_DlgMasterInfo;
CDlgSend(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CDlgSend)
enum { IDD = IDD_SEND };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgSend)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CDlgSend)
afx_msg void OnBtnRevise();
virtual BOOL OnInitDialog();
afx_msg void OnRbtnSelfselect();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DLGSEND_H__F6DFADF2_D691_4A49_960B_FC24C0C17CA7__INCLUDED_)
// DlgSend.cpp : implementation file
//#include "stdafx.h"
#include "InfoSender.h"
#include "DlgSend.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CDlgSend dialog
CDlgSend::CDlgSend(CWnd* pParent /*=NULL*/)
: CDialog(CDlgSend::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgSend)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgSend::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgSend)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgSend, CDialog)
//{{AFX_MSG_MAP(CDlgSend)
ON_BN_CLICKED(IDC_BTN_REVISE, OnBtnRevise)
ON_BN_CLICKED(IDC_RBTN_SELFSELECT, OnRbtnSelfselect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDlgSend message handlers
BOOL CDlgSend::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CDlgSend::OnBtnRevise()
{
// TODO: Add your control notification handler code here
m_DlgMasterInfo.DoModal();
}void CDlgSend::OnRbtnSelfselect()
{
// TODO: Add your control notification handler code here
m_DlgSiteSelect.DoModal();
MessageBox("Love!");
}
// CDlgMasterInfo m_DlgMasterInfo;
头文件这两个对话框的声明,只要注释掉其中任何一个就没有问题了,只要两个同时存在,就会出现上述的问题!
CDlgSiteSelect *m_DlgSiteSelect;
CDlgMasterInfo *m_DlgMasterInfo;CDlgSend::CDlgSend(CWnd* pParent /*=NULL*/)
: CDialog(CDlgSend::IDD, pParent)
{
m_DlgSiteSelect = (CDlgSiteSelect *)new CDlgSiteSelect;
m_DlgMasterInfo = (CDlgMasterInfo *)new CDlgMasterInfo;
//{{AFX_DATA_INIT(CDlgSend)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
另外加一个析构函数delete这两个指针。
CDlgMasterInfo m_DlgMasterInfo;不要把对话框对象当作成员变量。
CDlgSiteSelect m_DlgSiteSelect;的实际意义是调用构造函数CDlgSiteSelect(NULL),并作一些初始化,
但此时父窗口还没创建出来,会有问题的
SOURCE=.\DlgXXX.cpp
# End Source File
# Begin Source File
SOURCE=.\DlgXXX.cpp
# Begin Source File
# End Source File
这样的文件,删掉,保存,然后再编译程序就没有问题了,这是为什么呢?
//#include "stdafx.h"
#include "InfoSender.h"
#include "DlgSend.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CDlgSend dialog
CDlgSend::CDlgSend(CWnd* pParent /*=NULL*/)
: CDialog(CDlgSend::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgSend)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}CDlgSend::~CDlgSend()
{
delete pDlgMasterInfo;
delete pDlgSiteSelect;
}
void CDlgSend::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgSend)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgSend, CDialog)
//{{AFX_MSG_MAP(CDlgSend)
ON_BN_CLICKED(IDC_BTN_REVISE, OnBtnRevise)
ON_BN_CLICKED(IDC_RBTN_SELFSELECT, OnRbtnSelfselect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDlgSend message handlers
BOOL CDlgSend::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CDlgSend::OnBtnRevise()
{
// TODO: Add your control notification handler code here
pDlgMasterInfo = (CDlgMasterInfo *)new CDlgMasterInfo;
pDlgMasterInfo->DoModal();
}void CDlgSend::OnRbtnSelfselect()
{
// TODO: Add your control notification handler code here
pDlgSiteSelect = (CDlgSiteSelect *)new CDlgSiteSelect;
pDlgSiteSelect->DoModal();
}