Say, I create a dialog window from my context menu that could be invoked by right-clicking the tray icon of my application:
CDialogDerivedClass dlg;
dlg.DoModal();
In case a user right-clicks my context menu again and picks another command I need to close that dialog window and show another one. I thought that simply sending WM_CLOSE to that first window would do the trick:
dlg.SendMessage(WM_CLOSE);
but evidently it messes something up inside the MFC class because that dialog's CDialogDerivedClass::OnDestroy() method is never called at that moment. This only happens when my app or its process exits (way later.)
So I'm curious, how do you close the MFC's CDialog derived class from outside (from the same / main thread)?
DestroyWindow
to close it. – Roger Rowland