Defining Names for the Preprocessor

You can specify conditional branching in a resource script file, based on whether or not a term is defined in the Defines edit field of the Customize Resource Options dialog box (Figure 7.3) or with the /D option.

For example, suppose your application has a menu, the Debug menu, which you want to appear only during debugging. When you compile the application for normal use, the Debug menu is excluded. The resource script file contains the following statements to define the Debug menu:

MainMenu MENU

BEGIN

.

.

.

#ifdef DEBUG

POPUP “&Debug”

BEGIN

MENUITEM “&Memory usage”, ID_MEMORY

MENUITEM “&Walk data heap”, ID_WALK_HEAP

END

#endif

END

When building a debugging version of the application, you include the Debug menu by defining DEBUG in either the Defines edit box or using the /D option:

/D DEBUG

To build a normal version of the application—one that does not include the Debug menu—you would delete the word DEBUG from the Defines edit field or remove the /D option.