CDialog::DoModal(), CDialog::EndDialog() Design Flaw 
Author Message
 CDialog::DoModal(), CDialog::EndDialog() Design Flaw

I ran into a problem using MFC CDialog based dialogs where the dialog would
become
modeless after the call to DoModal().  There appears to be a problem in
MFC's implementation
that if more than one modal dialog is displayed by an application, then when
the first one is
removed via CDialog::EndDialog() then the others are no longer modal.

This seems to stem from what I think is an inconsistency or design flaw in
MFC's implementation
of CDialog.

CDialog mimics modality by disabling the parent windows of a dialog and
running a separate message loop from within the DoModal() code.
CDialog::DoModal() does not
call the Win32 DialogBox() routine to create the dialog box.  DoModal()
calls
CreateDialogIndirect() to create the modeless dialog.  Therefore according
to the Win32 documentation, any
dialog created with CreateDialogIndirect() should be removed using
DestroyWindow().
However, CDialog::EndDialog() calls the Win32 EndDialog() function.  This
seems to be a mismatch in the
use of Win32 functions by MFC's CDialog implementation.

The problem with this is that when the Win32 EndDialog() is called it
re-enables the parent windows
of the dialog.  MFC's implementation wants to wait until the message loop is
exited before the
parent windows are enabled.  Invoking CDialog::EndDialog() which calls Win32
EndDialog() will re-enable
the parent windows too soon.  And if any other CDialog based dialogs have
been displayed as
a result of messages processed and dispatched by the message loop of the
first CDialog then
their parent windows may be re-enabled (if the parent windows are the same)
and thus there is a
loss of modality.

Has anyone else run into problems with CDialog based dialogs losing
modality?

Is there a MFC design flaw here?

Comments are appreciated.

Jim Boyle



Tue, 23 Aug 2005 04:16:05 GMT  
 CDialog::DoModal(), CDialog::EndDialog() Design Flaw
Jim,

I don't recall ever having this problem, but maybe it's that old
charmed-life curse I suffer. Anyway, I just created a Wizard generated
dialog-based app that clones itself on the press of a button, and I'm
not having an easy time reproducing it. If nobody else comes along with
greater insight, you could -- it you want, email me a test project, and
I'll be glad to take a look at it.
--
Jeff Partch [VC++ MVP]


Quote:
> I ran into a problem using MFC CDialog based dialogs where the dialog
would
> become
> modeless after the call to DoModal().  There appears to be a problem
in
> MFC's implementation
> that if more than one modal dialog is displayed by an application,
then when
> the first one is
> removed via CDialog::EndDialog() then the others are no longer modal.

> This seems to stem from what I think is an inconsistency or design
flaw in
> MFC's implementation
> of CDialog.

> CDialog mimics modality by disabling the parent windows of a dialog
and
> running a separate message loop from within the DoModal() code.
> CDialog::DoModal() does not
> call the Win32 DialogBox() routine to create the dialog box.
DoModal()
> calls
> CreateDialogIndirect() to create the modeless dialog.  Therefore
according
> to the Win32 documentation, any
> dialog created with CreateDialogIndirect() should be removed using
> DestroyWindow().
> However, CDialog::EndDialog() calls the Win32 EndDialog() function.
This
> seems to be a mismatch in the
> use of Win32 functions by MFC's CDialog implementation.

> The problem with this is that when the Win32 EndDialog() is called it
> re-enables the parent windows
> of the dialog.  MFC's implementation wants to wait until the message
loop is
> exited before the
> parent windows are enabled.  Invoking CDialog::EndDialog() which calls
Win32
> EndDialog() will re-enable
> the parent windows too soon.  And if any other CDialog based dialogs
have
> been displayed as
> a result of messages processed and dispatched by the message loop of
the
> first CDialog then
> their parent windows may be re-enabled (if the parent windows are the
same)
> and thus there is a
> loss of modality.

> Has anyone else run into problems with CDialog based dialogs losing
> modality?

> Is there a MFC design flaw here?

> Comments are appreciated.

> Jim Boyle



Tue, 23 Aug 2005 04:43:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: How to move a CDialog before calling DoModal()

2. Q: CDialog::DoModal () fails

3. CDialog::DoModal

4. Using DoModal from CDialog when called from a DLL

5. CDialog.DoModal problem

6. Help. CDialog::DoModal Fail in _beginthreadex

7. CDialog::DoModal() Behaviour

8. Invalid Page Fault from CDialog.DoModal()

9. Calling CDialog::DoModal crashes

10. CDialog::DoModal()

11. CDialog::DoModal() keyboard messages?????

12. HELP! CDialog/DoModal problems in regular DLL

 

 
Powered by phpBB® Forum Software