Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a modeless dialog to modal at runtime

I have a dialog (CDialog derived class) that can be used in two different ways (edition mode and programming mode).

When the dialog is open to be used in programming mode it is a modeless dialog that it is used for modifying the main view (kind of a toolbar). When it is open in edition mode the user can change the configuration of the dialog itself and in this case it is a modal dialog.

Right now they are two different dialogs with few differences and I would like to have just want dialog and let the user change between programming mode and edition mode just by pressing a button in the dialog.

So I need to convert the modeless dialog in a modal dialog and vice versa at runtime. Is there a way to achive that?

Thanks.

like image 860
Javier De Pedro Avatar asked Aug 04 '09 06:08

Javier De Pedro


People also ask

What is the difference between modal and modeless dialog box?

Modal dialog boxes, which require the user to respond before continuing the program. Modeless dialog boxes, which stay on the screen and are available for use at any time but permit other user activities.

Is a dialog box a modal?

Definition: A modal dialog is a dialog that appears on top of the main content and moves the system into a special mode requiring user interaction. This dialog disables the main content until the user explicitly interacts with the modal dialog.

What is the example of modeless dialog box?

Here is an example: The Find (and the Replace) dialog box of WordPad (also the Find and the Replace dialog boxes of most applications) is an example of a modeless dialog box. If it is opened, the user does not have to close it in order to use the application or the document in the background.

How do you make a modeless dialog box?

To create a modeless dialog box, call your public constructor and then call the dialog object's Create member function to load the dialog resource. You can call Create either during or after the constructor call. If the dialog resource has the property WS_VISIBLE, the dialog box appears immediately.


2 Answers

As maybe someone could be interested in doing something similar in the future, this is the way I eventually did it:

I use this two functions of main frame: CMainFrame::BeginModalState() and CMainFrame::EndModalState().

The problem with these functions is the same that with disabling the parent window. The window you want to make modal also gets disabled. But the solution is easy, just re-enable the window after calling BeginModalState.

void CMyDialog::MakeModal()
{
   //disable all main window descendants
   AfxGetMainWnd()->BeginModalState();

   //re-enable this window
   EnableWindow(TRUE);
}

void CMyDialog::MakeModeless()
{
   //enable all main window descendants
   AfxGetMainWnd()->EndModalState();
}

Thanks for your help.

like image 192
Javier De Pedro Avatar answered Sep 30 '22 09:09

Javier De Pedro


That can't be done easily without closing and reopening the dialog. Then you can call ShowWindow or DoModal as appropriate.

like image 44
demoncodemonkey Avatar answered Sep 30 '22 09:09

demoncodemonkey