繁体   English   中英

当另一个窗口关闭时,关闭无模式对话框

[英]Close modeless dialog when another window closes

我有一个如下所示的无模式对话框,

CPlotDlg * newd = new CPlotDlg ();
newd->Create(IDD_PLOT,this->GetParentOwner());
newd->SetParent(this->GetParentFrame()->GetParent());
newd->ShowWindow(SW_SHOW);

我想在其他窗口(而不是父窗口)关闭时关闭此对话框。 我该如何实现? 谢谢。

只需将CPlotDlg *保存到其他窗口中即可关闭CPlotDlg窗口。

如果更接近的窗口是SomeWhereDlg,

class SomeWhereDlg
{
  public:
  ...
  ...
  CPlotDlg* m_plotDlg;
};

void SomeWhereDlg::SetPlotDlg(CPlotDlg* plotDlg)
{
  ASSERT(plotDlg);
  if(plotDlg == nullptr) { return;}

  m_plotDlg = plotDlg;
}

然后,在创建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);

如果发生关闭事件,只需通过m_plotDlg调用Close()或delete等。

要关闭无模式对话框,请将指针保存为CodeDreamer所示,然后调用m_plotDlg-> DestroyWindow()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM