小弟我在程序中做了一个CPropertySheet/CPropertyPage模式的向导对话框。现在模式的向导对话框满足不我的需求,我将它改为非模式的向导对话框,可当我点击向导框的取消按钮时,程序“死”了。于是我就想在取消按钮的时候响应DestroyWindow();,另在OnDestroy()中delete this;, 可程序运行时,点击取消按钮时,程序还是“死”了。不知道那位高手能替小弟看下,小弟在此先谢谢了!程序的主要代码:
——————————————————————————————————————————————
创建,显示:
CAdd *m_pAdd;                  //class CAdd : public CPropertySheet
        m_pAdd = new CAdd;
m_pAdd->Create();
m_pAdd->ShowWindow(SW_SHOW);有3个CPropertyPage页面,CAdd1为第一个向导页,我点击的取消按钮函数:
void CAdd1::OnCancel() 
{
// TODO: Add your specialized code here and/or call the base class
CPropertyPage::OnCancel();
DestroyWindow(); 
}CAdd的OnDestroy函数:
void CAdd::OnDestroy() 
{
CPropertySheet::OnDestroy();
// TODO: Add your message handler code here
AfxMessageBox("delete this");
delete this;
}
——————————————————————————————————————————————
到底是什么原因呢?是不是在CAdd1::OnCancel()没调用到CAdd::OnDestroy()呢?
嗨~
大家帮帮忙呀~!~!
主要的代码在这了,还缺什么代码我将回帖贴上。

解决方案 »

  1.   

    建议你还是用一个线程DoModal吧。
      

  2.   

    PROPSHEETHEADER结构中的dwFlags成员要添加PSH_MODELESS标志,像下面的代码这样:
    m_pAdd = new CAdd;
    m_pAdd->m_psh.dwFlags |= PSH_MODELESS;
    m_pAdd->Create();
      

  3.   

    If you implement the OK button in a modeless dialog box, you must override the OnOK member function and call DestroyWindow from within it. Don’t call the base-class member function, because it calls EndDialog, which makes the dialog box invisible but does not destroy it
    这是MSDN上的CDialog的一段话,说非模态对话框不要调用父类的函数OnOK,OnCancel之类的会关闭的函数。