Dialog Modality

Dialog Modality—Modal or Modeless Dialogs
A dialog can be used in two ways. Basically, it either blocks access (by mouse or keyboard) to any other parts if an application while
visible, or it does not impose any restrictions to what the user can do. The first approach is known as modal dialog behavior, and the second
is modeless dialog behavior.

The decision when to use a modal or modeless dialog depends very much on the dialog itself and on what the purpose of the dialog is. At one
extreme: In a situation where you cannot do any useful work until a decision has been made and the dialog has been closed, you can safely go
for a modal dialog. A file selector is a typical example and is often implemented as a modal dialog. At the opposite end of the scale, a
search dialog is modeless in most cases. Modeless dialogs introduce greater flexibility for end users because they are not forced to work in
a specific pattern decided by the developer. The cost for the greater flexibility is that the code required to make a modeless dialog work as
intended can be somewhat more complicated. However, if it is possible, you will normally get a better result using modeless dialogs. The
standard KDE file selector can be used as a modeless dialog, and a dialog derived from the KDialogBase class can be either modal or modeless.
For a developer, the main differences between modal and modeless dialogs are how the dialog becomes visible and how it can transfer
information—that is, the dialog settings—to the rest of the program.

打开一个模式对话框后,其他所有对话框都不能用鼠标和键盘操作!非模对话框打开后,它下面的对话框还能操作。仅此而已!应用的时候,如果希望多个对话框
能同时操作,就用非模态的,大多情况下是模态的,好控制!

无模式总结:创建时用Create,清除时用DestroyWindow,创建对象时用new,清除对象时用 CDialog::PostNcDestroy并执行delete   this语句。非模态对话
框的生存周期较长,其对象的生存周期需要存在于父窗口类对象的整个生存周期。因此需要在父窗口类添加指向非模态对话框类对象的指针成员变量。
模式总结:创建时用DoModal,清除时用EndDialog,对象的创建正常,并且利用析构函数清除对象。
原文地址:https://www.cnblogs.com/taoxu0903/p/1431222.html