Dialog Boxes

A dialog box is a temporary window that contains controls. You can use it to display status information and to get input from the user. Most applications use dialog boxes to prompt for additional information. Many applications also use dialog boxes to display information or options while the user works in another window. For example, word processing applications often use a dialog box with a text-search command. While the application searches for text, the dialog box remains on the screen. The user can return to the dialog box and continue searching for the word or search for a new word. Applications that use dialog boxes in this way create a dialog box when the user chooses a command. The application continues to display the dialog box for as long as the application runs or until the user closes the dialog box.

Windows CE supports two types of dialog boxes to accommodate different application uses — modal and modeless. A modal dialog box requires the user to supply information or dismiss the dialog box before allowing the application to continue. Applications use modal dialog boxes in conjunction with commands that require additional information before they can proceed. A modeless dialog box allows the user to supply information and return to a previous task without closing the dialog box. Modal dialog boxes are simpler to manage than their modeless counterparts because they are created, perform their task, and are destroyed by calling a single function.

To create either a modal or modeless dialog box, you must supply a dialog box template to describe the dialog box style and content. You must also supply a dialog box procedure to carry out tasks. The dialog box template is a binary description of the dialog box and the controls it contains. You can create this template as a resource that you can load from your executable file. The dialog box procedure is an application-defined callback function that the system calls when it has input for the dialog box or tasks for the dialog box to carry out. Although a dialog box procedure is similar to a window procedure, it does not have the same responsibilities.

You typically create a dialog box by using either the DialogBox or CreateDialog function. DialogBox creates a modal dialog box; CreateDialog creates a modeless dialog box. These two functions load a dialog box template from your executable file and create a pop-up window that matches the template's specifications. There are other functions that create a dialog box by using templates in memory; they pass additional information to the dialog box procedure as the dialog box is created.

Dialog boxes usually belong to a predefined, exclusive window class. The system uses this window class and its corresponding window procedure for both modal and modeless dialog boxes. When the function is called, it creates the window for the dialog box, as well as the windows for the controls in the dialog box, and then sends selected messages to the dialog box procedure. While the dialog box is visible, the predefined window procedure manages all messages, processing some messages and passing others to the dialog box procedure so that the procedure can carry out tasks. You do not have direct access to the predefined window class or window procedure, but you can use the dialog box template and dialog box procedure to modify the style and behavior of a dialog box. Dialog box types are described in the following table.

Dialog box type Description
Application-defined dialog box Helps a user perform tasks specific to an application.
Common dialog box Provides a familiar way for users to perform tasks that are common to many applications.
Message box Notifies a user of an event or situation and offers limited responses.
Property Sheet, a collection of tabbed dialog boxes Provides a convenient way to view and modify object properties. These are discussed in Foundation Controls.