今天改项目中的一个Bug,遇到一个问题不太清楚,希望高手解答!假设对话框A类型的指针pA是对话框B的成员变量,B调用pA创建A对话框,在A中调用了OnCancel函数后,pA并没有赋为NULL,B调用pA依然可以将A显示出来,功能也正常,程序没有崩溃,我觉得不太理解,A不是已经destroy了吗,为什么依然可以show出来?另外,B最小化后再还原,A就消失了,这又是为什么?

解决方案 »

  1.   

    你这个应该是非模态对话框吧
    MSDN中有一段话解释得很清楚:
    If you implement the Cancel button in a modeless dialog box, you must override the OnCancel member function and call DestroyWindow from within it. Don't call the base-class member function, because it calls EndDialog, which will make the dialog box invisible but not destroy it.
    对于非模态对话框来说,OnCancel并不真正的关闭对话框,而只是将它隐藏了起来。
      

  2.   

    Override this method to perform actions (such as restoring old data) when a user closes the dialog box by clicking Cancel or hitting the ESC key. The default closes a modal dialog box by calling EndDialog and causing DoModal to return IDCANCEL.If you implement the Cancel button in a modeless dialog box, you must override the OnCancel method and call DestroyWindow inside it. Do not call the base-class method, because it calls EndDialog, which will make the dialog box invisible but not destroy it.