Click to See Complete Forum and Search --> : Conflicting Modal Dialogs


May 6th, 1999, 11:22 AM
I have two modal dialog problems which may or may not be related:
Case 1: I have a dialog with an Apply button so that settings changes happen on the main window without dismissing the dialog. However, during the update of the main window it is possible for a modal dialog to be created. When this second dialog is dismissed, the first is no longer modal.

Case 2: I have a worker thread which can cause a modal dialog to be displayed. It does this by posting a message to the main window, and waiting for the main thread to signal the worker thread to continue. In the meantime the main thread displays the modal dialog. However, as for case 1, there may already be a modal dialog on screen when the dialog is displayed on behalf of the worker thread, and the same problems arise.

Any simple code (preferred) or strategies for workarounds would be appreciated.

Derek

May 7th, 1999, 09:10 AM
In case its of use to someone else, the following override of DoModal appears
to do the trick.

int CMyDialog::DoModal()
{
//Find the current active window (which may be another modal dialog)
//and disable it
HWND hActiveWindow = ::GetActiveWindow();
::EnableWindow(hActiveWindow, FALSE);

//Call the base class
int status = CDialog::DoModal();

//disable the main window to undo the actions of CDialog::DoModal
//which enables the main window in PostModal
CWnd* pWnd = AfxGetMainWnd();
pWnd->EnableWindow(FALSE);

//re-enable the previously active window (which may be a modal dialog
//or the main window (or something else ?)
//if main window was active, then we'll just be re-enabling it here
::EnableWindow(hActiveWindow, TRUE);
::SetActiveWindow(hActiveWindow);
::SetFocus(hActiveWindow);

return status;
}

Derek.