A dialog procedure is a special type of window procedure that is associated with a modal dialog box and processes messages intended for that dialog box. The structure of a dialog procedure is similar to that of a "normal" window procedure, and it processes messages in the same way, although certain message classes received by a dialog procedure are different from those received and processed by a normal window procedure. The structure of a typical dialog procedure is shown in Figure "Structure of a Dialog Procedure".
Since modal dialog boxes do not belong to a class, they are not registered to Presentation Manager in the manner of a normal window. A dialog procedure is associated with a dialog box as part of a WinDlgBox() call, which loads a modal dialog box and processes the dialog as a single operation, or a WinLoadDlg() call, which loads the dialog box into memory but does not process it; the dialog box may subsequently be processed by a WinProcessDlg() call. The processes of providing input to and obtaining results from a dialog procedure are discussed in Building a Presentation Manager Application.
Note that since a modeless dialog box is simply an optimized (non-sizable) window with no other inherent properties such as modality, it receives the same messages as a standard window, and its methods are therefore contained within a normal window procedure rather than a dialog procedure.
Note that a dialog box must use the system linkage convention, since it is simply a specialized form of window procedure. This is achieved using the EXPENTRY keyword.
Upon creation, a dialog box receives a message of the system-defined class WM_INITDLG. This is similar to the WM_CREATE message received by a normal window upon creation, and may be processed in a similar way. The first parameter in the WM_INITDLG message may be used to pass a pointer to the dialog procedure, referencing a data structure containing initialization information or other application-specified data.
A dialog box also receives messages of class WM_CONTROL indicating events occurring in control windows within the dialog box. The window identifier of the control window that dispatched the message, along with the nature of the message, is indicated in the message parameters. The WM_CONTROL message is described in the IBM OS/2 Version 2.0 Presentation Manager Reference. The dialog procedure may wish to explicitly process events indicated by WM_CONTROL messages, or it may allow such messages to pass on to the default Presentation Manager-supplied dialog procedure WinDefDlgProc().
A dialog box also typically receives WM_COMMAND messages, which are generated when a pushbutton within the dialog box is pressed by the user. The identity of the pushbutton is indicated in the first parameter of the WM_COMMAND message.
The symbolic names DID_OK and DID_CANCEL are defined by Presentation Manager, and by convention are used to refer to the "OK" and "Cancel" pushbuttons respectively. The definition of dialog boxes is described in detail in Presentation Manager Resources.
A dialog procedure is terminated and the dialog box is destroyed when the dialog procedure issues a WinDismissDlg() call to Presentation Manager, typically as a result of the user pressing a pushbutton. By convention, this call specifies a parameter indicating TRUE if the user completed the dialog by pressing an "Enter" or "OK" pushbutton, or FALSE if the user cancelled the dialog by pressing a "Cancel" pushbutton. The value specified in this parameter is returned to the window procedure that issued the WinDlgBox() or WinProcessDlg() call, as the return value from that call.
Message boxes do not require an application-supplied procedure to carry out their processing. The simple nature of the message box dialog allows it to be processed by Presentation Manager on the application's behalf, and to return the result to the application for subsequent action.