Creating a Resource Script File

After creating individual resource files for your application's icon, cursor, bitmap, and dialog resources, you create a resource script file. A resource script file is an ASCII text file with the file extension .RC (hence the name “RC file”).

NOTE:

If you use the QuickCase:W interface prototyper, the resource script file is created for you automatically.

The .RC file lists every resource in your application and describes some types of resources in great detail:

For resources that exist in a separate file, such as icons and cursors, the .RC file simply names the resource and the file that contains it.

For some types of resources, such as menus, the entire definition of the resource exists within the .RC file.

Lines in an .RC file cannot exceed 256 characters. They can contain resource statements, directives, or both:

Statements name and describe each resource.

Directives instruct the Resource Compiler to perform actions on the resource script file before compiling it. Directives can also assign values to names.

A description is given below of the statements and directives you can use in a resource script file. (For detailed descriptions and syntax, see Chapter 8, “Resource Script Statements.”)

Single-Line Statements

BITMAP

Defines a bitmap by naming it and specifying the file that contains it. (To use a particular bitmap, the application requests it by name.)

CURSOR

Defines a cursor by naming it and specifying the file that contains it. (To use a particular cursor, the application requests it by name.)

FONT

Specifies a file that contains a font.

ICON

Defines an icon by naming it and specifying the file that contains it. (To use a particular icon, the application requests it by name.)

Multiple-Line Statements

ACCELERATORS

Defines menu accelerator keys.

DIALOG

Defines a template that an application can use to create dialog boxes.

MENU

Defines the appearance and function of an application menu.

RCDATA

Defines raw data resources. Raw data resources let you include binary data directly into the executable file.

STRINGTABLE

Defines string resources. String resources are null-terminated ASCII strings that can be loaded from the executable file.

Directives

#define

Defines a specified name by assigning it a given value.

#elif

Marks an optional clause of a conditional compilation block.

#else

Marks the last optional clause of a conditional compilation block.

#endif

Marks the end of a conditional compilation block.

#if

Carries out conditional compilation if a specified expression is true.

#ifdef

Carries out conditional compilation if a specified name is defined.

#ifndef

Carries out conditional compilation if a specified name is not defined.

#include

Copies the contents of a file into the resource script before the Resource Compiler processes the script.

#undef

Removes the current definition of the specified name.

User-Defined Resources

Any data supplied by the user that needs to be added to the executable file.

NOTE:

Although the Resource Compiler can create font resources, Microsoft QuickC for Windows does not include the special tools needed to design custom fonts.

As an example, the following script file defines the resources for a C application called “Shapes”. Refer to the numbered paragraphs below for an explanation of each section of code.

1 #include “SHAPES.H”

2 ShapesCursor CURSOR SHAPES.CUR

3 ShapesIcon ICON SHAPES.ICO

4 ShapesMenu MENU

5 BEGIN

POPUP “&Shape”

BEGIN

MENUITEM “&Clear”, ID_CLEAR

MENUITEM “&Rectangle”, ID_RECT

MENUITEM “&Triangle”, ID_TRIANGLE

MENUITEM “&Star”, ID_STAR

MENUITEM “&Ellipse”, ID_ELLIPSE

END

END

1 The file uses the #include directive to include the contents of the header file SHAPES.H.
2 The CURSOR statement names the application's cursor resource ShapesCursor and specifies the cursor file SHAPES.CUR.
3 It does the same for the application's icon resource, ShapesIcon, using the ICON statement.
4 The script file uses the MENU statement to define an application menu named ShapesMenu, a pop-up menu with five menu items.
5 The menu definition, enclosed in the BEGIN and END key words, specifies each menu item and the menu ID code that is returned when the user selects that item. For example, the first item on the menu, Clear, returns the menu ID code ID_CLEAR when the user selects it. The ID values are defined in the application header file, SHAPES.H.

For more information on the resource script file, the syntax of the resource statements, and how to create user-defined resources, see Chapter 8, “Resource Script Statements.”