对话框A创建对话框B,如下:
CDialog *m_pDlg = new CDialog;
m_pDlg.Create(IDD_DIALOG1, this->GetParent());
m_pDlg.ShowWindow(...);
this->ShowWindow(FALSE);对话框B有一按钮button
void CXXDlg::onButton()
{
this->GetParent()->ShowWindow(TRUE);
this->DestroyWindow();
}问题1:点击按钮button关闭对话框B后,m_pDlg的内存释放了没有?A中还需要delete m_pDlg么?
问题2:this->GetParent()->ShowWindow(TRUE);对话框A没有显示是怎么回事?
CDialog *m_pDlg = new CDialog;
m_pDlg.Create(IDD_DIALOG1, this->GetParent());
m_pDlg.ShowWindow(...);
this->ShowWindow(FALSE);对话框B有一按钮button
void CXXDlg::onButton()
{
this->GetParent()->ShowWindow(TRUE);
this->DestroyWindow();
}问题1:点击按钮button关闭对话框B后,m_pDlg的内存释放了没有?A中还需要delete m_pDlg么?
问题2:this->GetParent()->ShowWindow(TRUE);对话框A没有显示是怎么回事?
============
凡是new出来的都应该要delete
==============
ShowWindow函数没有用TRUE作参数的,一般显示是写作:ShowWindow(SW_SHOW);
问题不在于TRUE/FALSE还是SW_HIDE/SW_SHOW,我觉是是getparent的问题,可是我不不明白。如果在B中定义一个CDialog *pB,在A中将pB = this;
pB.ShowWindow(TRUE);就正常了。
============
问题在这里,你这里创建的B对话框的父窗口应该设为A窗口才对吧
改成这样试试:
m_pDlg.Create(IDD_DIALOG1, this);
将A对话框的父窗口指针传递给B对话框了。
在B中this->GetWindow(GW_HWNDLAST)获得的就是A对话框的指针