For example, try the following -
MDI application launches first modal dialog -
void CMainFrame::OnViewModal()
{
// TODO: Add your command handler code here
CModal dlg(this);
dlg.DoModal();
}
Button clicked on first modal dialog to launch modeless dialog. The modal dialog is the owner window of the modeless dialog. Dismissing the modal dialog will automatically close the modeless dialog.
void CModal::OnBnClickedLaunch()
{
// TODO: Add your control notification handler code here
CModeless *pModeless = new CModeless;
pModeless->Create(IDD_MODELESS, this);
pModeless->ShowWindow(SW_SHOW);
}
The user clicks a button on the modeless dialog to launch the second modal dialog. Before launching the second modal dialog, the modeless dialog disables its owner window and then enables it after DoModal() returns.
void CModeless::OnBnClickedLaunchModal2()
{
// TODO: Add your control notification handler code here
CModal2 dlg2(this);
CWnd *pOwner = GetOwner();
ASSERT(pOwner->IsKindOf(RUNTIME_CLASS(CModal))); // Make sure owner window is a CModal object
pOwner->EnableWindow(FALSE); // Disable first modal dialog so it can't be dismissed
dlg2.DoModal(); // Do second modal dialog
pOwner->EnableWindow(TRUE); // Enable first modal dialog
}