For convenience and to keep from introducing device-dependent values into the application code, applications use dialog boxes instead of creating their own windows. This device independence is maintained by using logical coordinates in the dialog-box template. Dialog boxes are convenient to use because all aspects of the dialog box, except how to carry out its tasks, are predefined. Dialog boxes supply a window class and procedure, and create the window for the dialog box automatically. The application supplies a dialog function to carry out tasks and a dialog-box template that describes the dialog style and content.
A modeless dialog box allows the user to supply information to the dialog box and return to the previous task without canceling or removing the dialog box. Modeless dialog boxes are typically used as a way to let the user continually supply information about the current task without having to select a command from a menu each time. For example, modeless dialog boxes are often used with a text-search command in word-processing applications. The dialog box remains displayed while the search is carried out. The user can then return to the dialog box and search for the same word again, or change the entry in the dialog box and search for a new word.
An application with a modeless dialog box processes messages for that box by using the IsDialogMessage function inside the main message loop. The dialog function of a modeless dialog box must send a message to the parent window when it has input for the parent window. It must also destroy the dialog box when it is no longer needed. A modeless dialog box can be destroyed by using the DestroyWindow function. An application must not call the EndDialog function to destroy a modeless dialog box.
A modal dialog box requires the user to respond to a request before the application continues. Typically, a modal dialog box is used when a chosen command needs additional information before it can proceed. The user should not be able to continue some other operation unless the command is canceled or additional information is provided.
A modal dialog box disables its parent window, and it creates its own message loop, temporarily taking control of the application queue from the main loop of the program. A modal dialog box is displayed when the application calls the DialogBox function.
By default, a modal dialog box cannot be moved by the user. An application can create a moveable dialog box by specifying the WS_CAPTION and, optionally, the WS_SYSMENU window styles.
The dialog box is displayed until the dialog function calls the EndDialog function, or until Windows is terminated. The parent window remains disabled unless the dialog box enables it. Note that enabling the parent window is not recommended since it defeats the purpose of the modal dialog box.
A system-modal dialog box is identical to a modal dialog box except that all windows, not just the parent window, are disabled. System-modal dialog boxes must be used with care since they effectively shut down the system until the user supplies the required information.