-1

I am a newbie and I want to learn but I can't find anything about this. I attached a dialog to the parent. but, when I close the parent the dialog stays open. the parent is an exe file that loads the dialog (DLL) and opens it (like a plugin). how can I check if the parent closed then the dialog will be closed too?

Bossa
  • 159
  • 1
  • 1
  • 9
  • If you are a newbie, don't start with MFC. You'll need to understand the basic rules first, before diving into a complex framework. In other words: Learn the Windows API and C first, before using *any* native-mode framework. See [this Q&A](https://stackoverflow.com/q/18165076/1889329) for details and rationale. – IInspectable Nov 01 '18 at 18:58

1 Answers1

0

When a window is about to be destroy , WM_DESTROY is sent to that window, you can add an event to the WM_DESTORY event on the parent Dialog, then on that function close the child dialog manually.

enter image description here

  • This is not required. An [owned window](https://learn.microsoft.com/en-us/windows/desktop/winmsg/window-features#owned-windows) is automatically destroyed, when its owner is destroyed. Likewise, a [child window](https://learn.microsoft.com/en-us/windows/desktop/winmsg/window-features#child-windows) is automatically destroyed before its parent is destroyed. Whatever the OP is doing to *"attach a dialog to the parent"* is at fault, and that needs to be fixed. – IInspectable Nov 02 '18 at 07:14
  • you are right about that, but he call the "parent" as an exe file not really a CDialog class, the child dialog is in a dll, you dont know for sure (and he does not explain) how this "child" window is created, anyway, he will decide based on his code how to fix it. – Ricardo FuMa Nov 02 '18 at 07:53
  • its a dll that run as plugin and the dialog created by `CWnd parent; parent.Attach(((HWND)handle)); MyDialog dialog(&parent); dialog.qParentWidget = qParentWidget; dialog.linker = linker; AfxEnableControlContainer(); dialog.DoModal(); parent.Detach();` – Bossa Nov 02 '18 at 11:23
  • @RicardoFuMa - I tried OnDestroy but no success (still, the dialog stay open if I close the parent) – Bossa Nov 02 '18 at 11:43
  • @bos: You are lacking fundamental understanding of the framework you are using, in this particular case it is how MFC's C++ wrappers relate to native windows. – IInspectable Nov 02 '18 at 13:07