RE: multiple modal dialogs
- From: "RainMan" <RainMan@xxxxxxxxxxxxx>
- Date: Mon, 2 May 2005 17:44:02 -0700
There are two different ways of showing dialogs: modal and modeless.
Without getting into deep details:
Modal dialog (and any window for that matter) runs on the top of all
disables window of the application that invoked modal dialog. You do it
calling
Modeless dialog is invoked using Create member of CDialog class.
While modal dialog relies on own message loop modeless relies on application
message loop.
Consider using modeless dialogs.
"Mihaly Marton" wrote:
> Hi,
>
> Anybody an idea how to have multiple modal dialogs in an application?
> I have an application that should allow multiple frame windows in the same
> time. The problem is, that these frame windows can have there own modal
> dialogs / message boxes. If a modal dialog (or message box) is open in one
> frame, and I switch to an other frame, and open there an other modal dialog
> (or a message box comes as a response to some event), the application enters
> in the modal loop if the new modal dialog. The problem is, that if the first
> modal dialog is closed with it's frame window, the frame window's object is
> destroyed, but the method in which was called the DoModal for the first
> modal dialog is not yet quit. This will happen only when the second modal
> dialog is closed, but this causes a crash, because the object of the frame
> window is already destroyed...
> Okay, it seems a bit complicated to understand even for me, so I'll try once
> again with code samples:
>
> I click some button in the first frame window, so this method will be
> called:
>
> void CMyFrame::OnClickButton()
> {
> CMyDialog dlg;
>
> dlg.DoModal(); // 1. Here is the first modal loop launched, from the
> first frame.
>
> // finish processing of button click
> }
>
> After the dialog is shown, I switch to the other frame, and click and other
> button, the following method will be called, but from inside of the
> DoModal's message loop:
>
> void CMyOtherFrame::OnClickButton2()
> {
> CMyOtherDialog dlg;
>
> dlg.DoModal(); // 2. Here enters the application in the second modal
> loop from the second frame
>
> // finish processing of the button click
> }
>
> Now I have two modal dialogs called from their frames.
> Now I'm switching back to the first frame, close the dialog and the frame...
> But a tricky thing happens. Even if I close the dialog, the DoModal cannot
> return, because the application is inside of the 2nd modal loop. So, the
> CMyFrame is destroyed when I close the frame window, but the
> CMyFrame::OnClickButton() method is not yet finished...
> Now I close the second modal dialog, so the modal loop ends, the second
> DoModal returns, so the control is back to the first modal loop. And this
> loop also ends because I already closed the window, so the first DoModal
> returns, but there is no object => application crashes (in the case when the
> rest of the metho uses the frame object...but this is generally the case)
> So, any ideas how to solve this problem? Either a solution that allows two
> modal dialogs without a crash, or other solution that disables somehow the
> existence of two modal dialogs...
>
>
>
.
- References:
- multiple modal dialogs
- From: Mihaly Marton
- multiple modal dialogs
- Prev by Date: RE: Detecting system shutdown in a spawned Win98 MFC Console app?
- Next by Date: Re: CMainFrame & OnMouseMove()
- Previous by thread: Re: multiple modal dialogs
- Next by thread: Stack, Heap, Mfc
- Index(es):