I have a first dialog with a simple button on it and while clicking the button, a second dialog is created using CDialog::Create(IDD,this)
. I would like the parent to be notified when the second dialog is destroyed but without adding any code to the second dialog i.e., without adding a m_pParent->Notify()
line in OnDestroy
method.
I have tried OnParentNotify
, PreTranslateMessage
, SubclassWindow
in the parent dialog with no success. I have not used the WS_CHILD
style for the second dialog. Any idea?
To complete: in fact, I have a ComboBox derived class (but the issue is the same with buttons) and I'm displaying a modeless Dialog instead of displaying the listbox. But I would like the control to be as generic as possible so that any modeless dialog could be used. That's why I do not want to add a specific notification in the second dialog. If I'm obliged, I will use this trick but I asked for a more generic solution. PreTranslateMessage
only catches WM_PAINT
, WM_NCMOUSELEAVE
and WM_NCMOUSEMOVE
.
Use a base class and have your parent refer to the modeless child by base class only. In the base PostNcDestroy
have it post to the parent.
It doesn't make sense to have the parent do a bunch of filtering / spying on all messages. It does make sense to implement behavior in a base class that you want to have common to all the different future flavors you might have of the modeless child.