我构建的一个窗体 对象在主窗体初始化的时候new出来。 如果关闭的话我只是发送一个WM_COLSE消息,但是不删除窗体的对象那么下次我接着创建出窗体,会不会有什么问题因为需要周期性的打开这个窗体。 

解决方案 »

  1.   

    如果是Create出来的,需要调用Destroy
      

  2.   

    创建之前判断一下窗口句柄是否不是空,是空的就不要创建了。不放心的话直接调用destroywindow()
      

  3.   

    WM_COLSE只是隐藏了对话框窗口,并没有销毁窗口,你可以使用ShowWindow(SW_SHOW)和ShowWindow(SW_HIDE)来控制对话框的显示与隐藏,如果想彻底销毁该窗口可以直接使用destroywindow()。你如果想多次new窗口的话,就必须使用destroywindow()销毁窗口后再创建新窗口。
      

  4.   

    A modal dialog box closes automatically when the user presses the OK or Cancel buttons or when your code calls the EndDialog member function.
    When you implement a modeless dialog box, always override the OnCancel member function and call DestroyWindow from within it. Don't call the base class CDialog::OnCancel, because it calls EndDialog, which will make the dialog box invisible but will not destroy it. You should also override PostNcDestroy for modeless dialog boxes in order to delete this, since modeless dialog boxes are usually allocated with new. Modal dialog boxes are usually constructed on the frame and do not need PostNcDestroy cleanup.