我在视图中通过调用OCREATE产生非模态对话框。消除对话框后,再次想产生这个对话框,程序就错误了,不知道什么问题啊?
代码如下:CColorDlg *p_ColorDlg = new CColorDlg;//定义为全局变量
void CPhototryView::OnMenuColor() 
{
// TODO: Add your command handler code here
    p_ColorDlg->Create(IDD_COLOR,this);
    p_ColorDlg->ShowWindow(SW_SHOW);
}void CColorDlg::OnClose() 
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
DestroyWindow ();
delete this;
p_ColorDlg = NULL;
}

解决方案 »

  1.   

    我想,问题出在这儿:
    delete this;
    你已经把分配的内存free了。我知道你是不想让内存泄露,但我认为既然你的
    CColorDlg *p_ColorDlg是全局变量,
    何不
    CColorDlg clrDlg;你认为呢?
      

  2.   

    何不在初始化中Create,在OnDestroy中delete,其他的地方 show 和 hide就好了
      

  3.   

    void CColorDlg::OnClose() 
    {
    // TODO: Add your message handler code here and/or call default
    CDialog::OnClose();
    DestroyWindow ();
    delete this;
    p_ColorDlg = NULL;
    }p_ColorDlg = NULL;这句话怎么来的呢?
    是不是将对话框的指针传进来了,要是传的话,请传2级指针,这样才能真正的将指向对话框的指针清空,是吧void CColorDlg::OnClose() 
    {
    // TODO: Add your message handler code here and/or call default
    CDialog::OnClose();
    DestroyWindow ();
    delete this;
    *pp_ColorDlg = NULL;   // 在创建对话框的时候,传进来的&p_ColorDlg
    }好运!
      

  4.   

    delete this将全局指针指向的资源释放,再次使用的时候,请别忘了再次申请空间。
      

  5.   

    我把delete this这句去掉,还是不可以啊。
    问题就出在我第二次调用 p_ColorDlg->Create(IDD_COLOR,this);
    的时候。
    “unhandled exception int myview.exe : ox500000 ”
    是不是p_ColorDlg这个全局变量的问题啊
      

  6.   

    在初始化里Create了,其他地方show 和hide就好了.
    因为你那样子会重复create的,