Creating a Dialog Box

The Dialog Editor is a tool that lets you design a dialog on-screen, much like a paint program. The Dialog Editor then writes a .DLG file, which describes the dialog in resource script statements, and an .H file, which contains any symbolic constants you've created in the dialog.

You then include the .DLG file in your application's resource script file. A resource script file contains definitions of resources to be used by the application, such as icons, cursors, and dialog-box templates.

When you create an About dialog box, the editor will create a .DLG file with the following resource script statements:

1 AboutBox DIALOG 22, 17, 144, 75

2 STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU

CAPTION “About Generic”

3 BEGIN

4 CTEXT “Microsoft Windows” -1, 0, 5, 144, 8

CTEXT “Generic Application” -1, 0, 14, 144, 8

CTEXT “Version 3.0” -1, 0, 14, 144, 8

5 DEFPUSHBUTTON ”OK" IDOK, 53, 59, 32, 14, WS_GROUP

END

In this example:

1 The DIALOG statement starts the dialog-box template. The name, AboutBox, identifies the template when the DialogBox function is used to create the dialog box. The box's upper-left corner is placed at the point (22,17) in the parent window's client area. The box is 144 units wide by 75 units high. The horizontal units are 1/4 of the dialog base width unit; the vertical units are 1/8 of the dialog base height unit. The current dialog base units are computed from the height and width of the current system font. The GetDialogBaseUnits function returns the dialog base units in pixels.
2 The STYLE statement defines the dialog-box style. This particular style is a window with a framed border, a caption bar, and a system menu, which is the typical style used for modal dialog boxes.
3 The BEGIN and END statements mark the beginning and end of the control definitions. The dialog box contains text and a default push button. The push button lets the user send input to the dialog function to terminate the dialog box.
  The statements, strings, and integers contained between the BEGIN and END statements describe the contents of the dialog box. (Because you would normally create such a description using the Dialog Editor, this guide does not describe the numbers and statements that make up the description. For a complete description of how to use the Dialog Editor, see the Toolkit.)
4 CTEXT creates a rectangle with the quoted text centered in a rectangle. This statement appears several times for the various texts that appear in the dialog box.
5 DEFPUSHBUTTON creates a push button that allows the user to give a default response; in this case, to choose the OK button, causing the dialog box to disappear.

The DS_MODALFRAME, WS_CAPTION, WM_SYSMENU, IDOK, and WS_GROUP constants used in the dialog-box template are defined in the Windows include file. You should include this file in the resource script file by using the #include directive at the beginning of the script file.

Fortunately, you won't need to become familiar with the details of the resource script language because the Dialog Editor handles it for you. For more information about using the Dialog Editor to create dialog boxes, see the Toolkit.)