Re: Dialog is changing from modal to modeless
On Feb 22, 6:47 am, Walter Eicher
<walter.eic...@nospam.microcrystal.ch> wrote:
Hi!
Under some conditions we show a modal dialog with two buttons [Yes]
and [No]. Sometimes when the user presses a button the dialog does not
disappear instead he changes to a modeless dialog. Normally it works
correct but maybe once a week the users see this effect.
The dialog is still working you can move it around and the buttons
reacting on pressing with closing the dialog. But between the first
and second button press, it is a modeless dialog. We could open other
dialogs.
This dialog resides in our standardDlg.dll wich is automatic loaded
when our application starts. I checked the code for opening this
dialog and it is as expected:
UINT InfoBox (const char* msg, UINT style, UINT icon, UINT defBtn)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CInfoDlg dlg(AfxGetMainWnd());
dlg.SetMessage (msg);
dlg.SetStyle (style);
dlg.SetIcon (icon);
dlg.SetDefaultBtn(defBtn);
return dlg.DoModal ();
}
Anyone an idea where i have to search for this crazy bug?
Best regards
Walter
Remember that in MFC, there is no such thing as a "modal" dialog, at
least not in the Win32 sense of modal dialogs. If MFC were to show a
truly modal dialog, then Windows would no longer pump messages through
the MFC message pump. Instead, Windows would run a modal message loop
on behalf of the application, which essentially steals the messages
from MFC's message pump. As a result, the MFC designers made a
conscious decision that the DoModal() function would actually show a
modeless dialog, doctored up so that it appeared to be a modal dialog
even though it's not. That way, all messages would still run through
the MFC message pump, even though a psuedo-modal-appearing dialog was
being displayed.
One consequence of this is an apparent bug in the way MFC-modal
dialogs are closed. If there are two or more MFC-modal dialogs, each
with the same parent, then closing one will unmask the true modeless
nature of the other. The bug, and one way to get more than one modal
dialog at a time, are explained at "The singular non-modality of MFC
modal dialogs", by Nishant Sivakumar, at http://www.codeproject.com/KB/dialo=
g/notmodaldialogs.aspx
Maybe the behavior you are seeing is related to the same bug.