Modal Dialog Boxes
A modal dialog box should be a pop-up window having a window menu, a
title bar, and a thick border; that is, the dialog box template should
specify the WS_POPUP, WS_SYSMENU, WS_CAPTION, and DS_MODALFRAME
styles. Although an application can designate the WS_VISIBLE style,
the system always displays a modal dialog box regardless of whether
the dialog box template specifies the WS_VISIBLE style. An application
must not create a modal dialog box having the WS_CHILD style. A modal
dialog box with this style disables itself, preventing any subsequent
input from reaching the application.
An application creates a modal dialog box by using either the
DialogBox
or DialogBoxIndirect
function. DialogBox
requires the name
or identifier of a resource containing a dialog box template;
DialogBoxIndirect
requires a handle to a memory object containing a
dialog box template. The DialogBoxParam
and DialogBoxIndirectParam
functions also create modal dialog boxes; they are identical to the
previously mentioned functions but pass a specified parameter to the
dialog box procedure when the dialog box is created.
When creating the modal dialog box, the system makes it the active
window. The dialog box remains active until the dialog box procedure
calls the EndDialog function or the system activates a window in
another application. Neither the user nor the application can make the
owner window active until the modal dialog box is destroyed.
When the owner window is not already disabled, the system
automatically disables the window and any child windows belonging to
it when it creates the modal dialog box. The owner window remains
disabled until the dialog box is destroyed. Although a dialog box
procedure could potentially enable the owner window at any time,
enabling the owner defeats the purpose of the modal dialog box and is
not recommended. When the dialog box procedure is destroyed, the
system enables the owner window again, but only if the modal dialog
box caused the owner to be disabled.
As the system creates the modal dialog box, it sends the WM_CANCELMODE
message to the window (if any) currently capturing mouse input. An
application that receives this message should release the mouse
capture so that the user can move the mouse in the modal dialog box.
Because the system disables the owner window, all mouse input is lost
if the owner fails to release the mouse upon receiving this message.
To process messages for the modal dialog box, the system starts its
own message loop, taking temporary control of the message queue for
the entire application. When the system retrieves a message that is
not explicitly for the dialog box, it dispatches the message to the
appropriate window. If it retrieves a WM_QUIT message, it posts the
message back to the application message queue so that the
application's main message loop can eventually retrieve the message.
The system sends the WM_ENTERIDLE message to the owner window whenever
the application message queue is empty. The application can use this
message to carry out a background task while the dialog box remains on
the screen. When an application uses the message in this way, the
application must frequently yield control (for example, by using the
PeekMessage function) so that the modal dialog box can receive any
user input. To prevent the modal dialog box from sending the
WM_ENTERIDLE messages, the application can specify the DS_NOIDLEMSG
style when creating the dialog box.
An application destroys a modal dialog box by using the EndDialog
function. In most cases, the dialog box procedure calls EndDialog when
the user clicks Close from the dialog box's window menu or clicks the
OK or Cancel button in the dialog box. The dialog box can return a
value through the DialogBox function (or other creation functions) by
specifying a value when calling the EndDialog function. The system
returns this value after destroying the dialog box. Most applications
use this return value to determine whether the dialog box completed
its task successfully or was canceled by the user. The system does not
return control from the function that creates the dialog box until the
dialog box procedure has called the EndDialog function.
and
Modeless Dialog Boxes
A modeless dialog box should be a pop-up window having a window menu,
a title bar, and a thin border; that is, the dialog box template
should specify the WS_POPUP, WS_CAPTION, WS_BORDER, and WS_SYSMENU
styles. The system does not automatically display the dialog box
unless the template specifies the WS_VISIBLE style.
An application creates a modeless dialog box by using the CreateDialog
or CreateDialogIndirect
function. CreateDialog
requires the name or
identifier of a resource containing a dialog box template;
CreateDialogIndirect
requires a handle to a memory object containing a
dialog box template. Two other functions, CreateDialogParam
and
CreateDialogIndirectParam
, also create modeless dialog boxes; they
pass a specified parameter to the dialog box procedure when the dialog
box is created.
CreateDialog
and other creation functions return a window handle for
the dialog box. The application and the dialog box procedure can use
this handle to manage the dialog box. For example, if WS_VISIBLE is
not specified in the dialog box template, the application can display
the dialog box by passing the window handle to the ShowWindow
function.
A modeless dialog box neither disables the owner window nor sends
messages to it. When creating the dialog box, the system makes it the
active window, but the user or the application can change the active
window at any time. If the dialog box does become inactive, it remains
above the owner window in the Z order, even if the owner window is
active.
The application is responsible for retrieving and dispatching input
messages to the dialog box. Most applications use the main message
loop for this. To permit the user to move to and select controls by
using the keyboard, however, the application must call the
IsDialogMessage
function. For more information about this function,
see Dialog Box Keyboard Interface.
A modeless dialog box cannot return a value to the application as a
modal dialog box does, but the dialog box procedure can send
information to the owner window by using the SendMessage
function.
An application must destroy all modeless dialog boxes before
terminating. It can destroy a modeless dialog box by using the
DestroyWindow
function. In most cases, the dialog box procedure calls
DestroyWindow
in response to user input, such as clicking the Cancel
button. If the user never closes the dialog box in this way, the
application must call DestroyWindow
.
DestroyWindow
invalidates the window handle for the dialog box, so any
subsequent calls to functions that use the handle return error values.
To prevent errors, the dialog box procedure should notify the owner
that the dialog box has been destroyed. Many applications maintain a
global variable containing the handle for the dialog box. When the
dialog box procedure destroys the dialog box, it also sets the global
variable to NULL, indicating that the dialog box is no longer valid.
The dialog box procedure must not call the EndDialog
function to
destroy a modeless dialog box.
When creating the modal dialog box, the system makes it the active
window. The dialog box remains active until the dialog box procedure
calls the EndDialog
function or the system activates a window in
another application. Neither the user nor the application can make the
owner window active until the modal dialog box is destroyed.
When the owner window is not already disabled, the system
automatically disables the window and any child windows belonging to
it when it creates the modal dialog box. The owner window remains
disabled until the dialog box is destroyed. Although a dialog box
procedure could potentially enable the owner window at any time,
enabling the owner defeats the purpose of the modal dialog box and is
not recommended. When the dialog box procedure is destroyed, the
system enables the owner window again, but only if the modal dialog
box caused the owner to be disabled.
https://docs.microsoft.com/en-us/windows/win32/dlgbox/about-dialog-boxes
So you must want your apps to crash.