Programming Tools:prgtools

Using constants with ARC.EXE Foundation

Instead of numeric IDs, #define constants can be used in an ARC file just as in a PRG file. This has the obvious advantage that resources can be identified in both ARC and PRG files using the same constants. To accomplish this, the constants are defined in a CH file. The resource compiler understands the directives #inlude, #define, #ifdef, #ifndef, #elseand #endif, and treats them in the same way as the Xbase++ compiler. Therefore, it is possible to declare resources in the following way:

** CH file: BITMAPID.CH               // Include file defines 
                                      // constants for 
#define ID_BMP_LOGO          10       // XPP.EXE and ARC.EXE 
#define ID_BMP_BACKGROUND    11 
#define ID_BMP_NEXT          12 
#define ID_BMP_PREVIOUS      13 

** EOF 

----------------------------------------------------------------- 

** ARC file: TEST.ARC                 // Declaration of resources 

#include "BitmapID.ch"                // Include CH file 

BITMAP                                // Keyword introduces 
   ID_BMP_LOGO       = "Logo.bmp"     // a block of resources 
   ID_BMP_BACKGROUND = "Backgrd.bmp"  // of the same type 
   ID_BMP_NEXT       = "Next.bmp" 
   ID_BMP_PREVIOUS   = "Prev.bmp" 

   #ifdef __OS2__                     // Conditional 
      100 = "\bitmaps\os2\test.bmp"   // compiling due to 
   #else                              // implicit constant 
      100 = "\bitmaps\w32\test.bmp" 
   #endif 

** EOF 

This example shows the code for a CH file which defines constants for the numeric resource IDs. The constants are used in the ARC file since ARC.EXE can resolve the #include directive.

Only bitmap resources are declared in the example. The keyword BITMAP is written in a separate line and is followed by a block of resource declarations of the same type. ARC supports this syntactical form for declaring resources which results in better readability of the ARC file. If a keyword is written on a line by itself, all following lines declare the same resource type without repeating the keyword.

The last lines in the example demonstrate how operating system-specific resources can be declared in one and the same ARC file. The directives #ifdef, #else and #endif are used, thus allowing for a conditional compilation. ARC.EXE uses the same implicit #define constants as the Xbase++ compiler: __OS2__ and __WIN32__.

Additionally, the resource compiler predefines a constant to identify the compiler. The #define is:

Predefined #define constant
#define Meaning
__ARC__ Xbase++ resource compiler in use

For example, if the same CH file is to be included from a PRG source file and from an ARC resource file then resource compiler specific directives can be hidden from the Xbase++ compiler as follows:

Header file "header.ch":

// ARC and XPP common code 
#define ICON_APPLICATION  100 
#define ICON_MAN          100 
// ARC specific code 
#ifdef __ARC__ 
   ICON 
      ICON_APPLICATION  =  "GROUP1.ICO" 
      ICON_MAN          =  "MAN.ICO" 
#endif 

In this way resource IDs and their associated source files can be maintained in the very same header file even so they are compiled by the Xbase++ compiler and the resource compiler.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.