1.7.2 Creating a Dialog Box

A dialog box is typically created by using either the CreateDialog or DialogBox function. These functions load a dialog box template from the application's executable file and then create a pop-up window that matches the template's specifications. The dialog box belongs to the predefined dialog box class unless another class is explicitly defined. The DialogBox function creates a modal dialog box; the CreateDialog function creates a modeless dialog box.

Use the WS_VISIBLE style for the dialog box template if you want the dialog box to appear upon creation.

1.7.2.1 Dialog Box Template

The dialog box template is a description of the dialog box: its height and width, the controls it contains, its style, the type of border it uses, and so on. A template is an application's resource. You use the Resource Compiler to convert the text description of the template to the required binary form and to add that binary form to the application's executable file.

Because a dialog box is system-independent, you can easily modify the template without changing the source code.

The CreateDialog or DialogBox function loads the resource into memory when it creates the dialog box and then uses the information in the dialog box template to create the dialog box, position it, and create and position the controls for the dialog box.

1.7.2.2 Dialog Box Measurements

Dialog box and control dimensions and coordinates are device-independent. Because a dialog box may be displayed on system displays that have widely varying pixel resolutions, dialog box dimensions are specified in system-character widths and heights instead of pixels. This ensures the best possible appearance of characters. One unit in the x-direction is equal to one-fourth of the dialog box base width unit. One unit in the y-direction is equal to one-eighth of the dialog box base height unit. The dialog box base units are computed from the height and width of the system font; the GetDialogBaseUnits function returns the dialog box base units for the current display. Applications can convert these measurements to pixels by using the MapDialogRect function.

Windows does not allow the height of a dialog box to exceed the height of a full-screen window, and it does not allow the width of a dialog box to be greater than the width of the screen.