[英]Close modeless dialog when another window closes
I have a modeless dialog which I'm creating as below, 我有一个如下所示的无模式对话框,
CPlotDlg * newd = new CPlotDlg ();
newd->Create(IDD_PLOT,this->GetParentOwner());
newd->SetParent(this->GetParentFrame()->GetParent());
newd->ShowWindow(SW_SHOW);
I want to close this dialog when a different window closes (not the parent). 我想在其他窗口(而不是父窗口)关闭时关闭此对话框。 How can I achieve this?
我该如何实现? Thanks.
谢谢。
Just, save CPlotDlg* to other window which will be used for closing CPlotDlg window. 只需将CPlotDlg *保存到其他窗口中即可关闭CPlotDlg窗口。
If the closer window is SomeWhereDlg, 如果更接近的窗口是SomeWhereDlg,
class SomeWhereDlg
{
public:
...
...
CPlotDlg* m_plotDlg;
};
void SomeWhereDlg::SetPlotDlg(CPlotDlg* plotDlg)
{
ASSERT(plotDlg);
if(plotDlg == nullptr) { return;}
m_plotDlg = plotDlg;
}
And then, when create CPlotDlg window, save the pointer. 然后,在创建CPlotDlg窗口时,保存指针。
CPlotDlg* newd = new CPlotDlg ();
//Save newd(CPlotDlg*) to somewhere
//i.e) specific window which will close this newd window
//SomeWhereDlg->SetPlotDlg(newd);
newd->Create(IDD_DIALOG1,this->GetParentOwner());
newd->SetParent(this);
newd->ShowWindow(SW_SHOW);
if a closing event occur, just call Close() or delete, etc via m_plotDlg. 如果发生关闭事件,只需通过m_plotDlg调用Close()或delete等。
要关闭无模式对话框,请将指针保存为CodeDreamer所示,然后调用m_plotDlg-> DestroyWindow()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.