USING THE DIALOG UTILITY

When you sit down to create a dialog box template, you'll discover that it's not quite as easy as it looks. Dialog boxes are an important part of your program, and the controls should be clearly and logically organized. But the process of placing and sizing these controls is mostly a matter of trial and error. You'll save yourself a lot of time and frustration by using the DIALOG program included with the Windows Software Development Kit. This program allows you to use the mouse to place controls within a dialog box frame, to move and resize them, and to give them various attributes.

Before you start haphazardly designing your dialog box in DIALOG, you should spend a little time in preparation. Although you can create a header file containing identifiers for the dialog box IDs, it's easier to create and edit the header file in a normal text editor. You should also have a general idea of how the controls will be arranged in the dialog box.

DIALOG can read .RES files (the binary compiled resource file, not the ASCII .RC resource script) and header files. DIALOG will prompt for the name of both a .RES file and a .H file when you choose Open from the File menu. Alternatively, you can read in a header file by using Open from the Include menu.

The names of all the dialog boxes currently stored in the .RES file are displayed when you choose View Dialog from the File menu. You can then pick one to edit. Thus, even if you begin by attempting to manually create a dialog box template in a .RC file and then give up in frustration, you can switch to DIALOG to get all the coordinates and sizes correct. Remember to compile the resource script before running DIALOG, however; as noted above, DIALOG cannot read .RC files, only compiled .RES files. Alternatively, you can begin a new dialog box by choosing New Dialog from the Edit menu.

You can fill up the dialog box with controls by choosing from the Control menu, which lists 13 basic types of controls such as Check Box, Radio Button, and Push Button. You then click the mouse where you want the control to be placed. If the control uses text, it will initially show only the string ”Text.“ You can select the control for editing merely by clicking on it. You can stretch or size it by hooking the little boxes on the sides or corners, and you can move it around by hooking the center.

The process of placing and sizing controls becomes a little easier if you first choose Grid from the Options menu and change both numbers to 2, thus forcing all dialog box coordinates and sizes to be in even numbers of units. Otherwise, you'll continually be wondering whether a particular control in a group is really one pixel or two pixels off or whether you've merely been looking at the screen too long. Also, try to create the controls in the order that you'll want them to appear in the dialog box template, because this in turn governs the order of tab stops and groups. Don't worry inordinately about getting it precisely right the first time through; as you'll see below, you can always change the order later.

One by one, select each control in the dialog box, choose Styles from the Edit menu, and enter the text of the control and the ID number in the Styles dialog box. If you've read in a header file, you can use the defined names rather than numbers for the IDs. You can also use the Styles dialog box to change the window style of the control. For instance, if you created a push-button control by choosing Push Button from the Control menu, you can make it a default push button by checking the Def Push Button box.

The dialog box you're creating is initially shown with a simple frame. To add a caption bar and a system menu box, select the dialog box itself with the mouse, and then choose Styles from the Edit menu. As you've seen, controls in a Windows dialog box are organized by ”groups“ and ”tab stops.“ You use the Tab key to move between controls marked as tab stops, and the arrow keys to move between controls within a group.

You can reorder the controls and select groups and tab stops through the Groups option of the Dialog menu, which displays a list of all the controls you've created. You can move a control by selecting it with the mouse and placing the horizontal black bar cursor in a new location. To define a group, you mark the first and last control of the group. You would also usually flag the first control of the group as a tab stop, but you can pick another control as the tab stop if you would like the cursor to jump to the middle of a group.

The best part of DIALOG is that you can try out these tab stops and groups to see if they work right. Simply choose Test from the Dialog menu. You can use both the keyboard and mouse to test how the input focus shifts between controls. (Don't expect radio buttons to work, however; they require some cooperation from a dialog box procedure.)

After you're done, you can save the file. DIALOG will actually save two files: a new .RES binary file containing the new dialog boxes and any changes to existing dialog boxes, and an ASCII file with the extension .DLG. The .DLG file contains the human-readable (well, almost readable) dialog box templates. All the controls will be expressed as CONTROL statements that include window style identifiers from WINDOWS.H. If you used names from a header file for the IDs, these names will be used in the .DLG file.

If you've changed the header file, you'll want to save that also. But beware: DIALOG will strip comments from it. For that reason, it's better to maintain the header file outside DIALOG and read it into DIALOG, rather than to save it from DIALOG.

DIALOG can't read or alter the ASCII .RC resource script file; it can't read .DLG files, either. DIALOG can read only the binary .RES file, which it saves in both the .RES and .DLG formats. If you create a dialog box in DIALOG and save it as MYPROG.RES and MYPROG.DLG (for instance), you should later edit the MYPROG.RC resource script and include the line:

rcinclude myprog.dlg

This allows the RC.EXE resource compiler to add the contents of the MYPROG.DLG file to the other resources included in MYPROG.RC. Do not use #include for the .DLG file. The RC.EXE resource compiler interprets only #define statements in any file included with #include. And if you started out by creating a dialog box in the MYPROG.RC resource script file and then edited it in DIALOG, you must also delete the original dialog box template from MYPROG.RC. Otherwise, you'll have two definitions for the same dialog box.

I have a confession to make. Although none of the dialog box templates in this chapter appear to be output from DIALOG, I originally created all of them in DIALOG. I later edited the .DLG files (and in many cases merged them into the .RC files) for the sole purpose of making them readable and presentable. DIALOG is almost essential when creating dialog boxes. Don't waste your time doing it any other way.