Discussion: The Supporting Files

The supporting files for Hello are given in Listings 3, 4, and 5. Listing 3 is the module-definition file, required for all Windows programs. Listing 4 is the resource script file, required of Windows programs that define their own resources, such as menus, dialogs, icons, and accelerators. Listing 5 is the resource include file, used to declare ID numbers associated with the resources. These files are provided on the distribution disks for your use, or you can create your own files based on the listings. The next sections explain each file.

The Module-Definition File

The module-definition file for Hello appears in Listing 3.

This file is typical for a Windows program. For more information on module-definition files, see the Windows SDK Guide to Programming and the Windows SDK Reference, Volume 2.

For programs that use the Microsoft Foundation Classes, always use FIXED for the CODE and DATA segments. C++ code can't be moved by the real-mode memory manager, so you must specify FIXED. Under protected mode, the protected-mode page manager will automatically take care of swapping the FIXED code in and out of memory.

You can simply use the HELLO.DEF file supplied on the distribution disks and modify it as needed for future programs. The values specified here are fairly standard for Windows programs, but you can adjust the HEAPSIZE or STACKSIZE values, for example, to suit your needs.

The Resource Script File

The resource script for Hello is shown in Listing 4.

This file specifies four resources: a custom icon, a menu, an accelerator table, and a dialog resource file created with a dialog editor.

The icon entry specifies an ID number, AFX_IDI_STD_FRAME, with which the icon resource can be loaded. The ID number is defined in the Microsoft Foundation Class Library. The icon entry uses an ICON statement to associate the ID number with a file that contains the icon data. If you supply an icon resource, you also must supply the file that contains that resource: for example, HELLO.ICO.

The menu entry defines a pop-up-style menu labeled “Help” with one menu item, labeled “About Hello...F1” The About menu command is associated with the ID number IDM_ABOUT, defined in the RESOURCE.H file (see the next section).

The accelerator table entry defines an accelerator table resource to associate keys with menu items. For Hello, the F1 function key displays the About dialog box by causing Windows to generate a WM_COMMAND message for the menu item. You saw previously how the OnAbout function handles that message.

The dialog resource file, which was created with a dialog editor, refers to a .DLG file containing a resource template. The template defines a dialog box resource to be used for the About dialog box. The dialog box has the caption, or window title, “About Hello” and contains several lines of text identifying the program. Hello's About dialog template is in the file HELLO.DLG on the distribution disks.

You can simply use the resource script provided on the distribution disks in file HELLO.RC. If you do not want to provide custom icons, you can remove the appropriate lines from the resource script. You will also need to remove them from the makefile.

The Resource Include File

Hello uses a file with the .H extension to define its application-specific resource ID numbers. The file appears in Listing 5. Hello's file defines only one resource ID.

This definition is used to match the About dialog resource in the .RC file with the CModalDialog object that uses the resource to create the dialog.

You can simply use RESOURCE.H on the distribution disks.