简体   繁体   中英

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.

If the closer window is 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* 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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