Fenestra User's Guide (appendix C) -- contents | previous | next
Under Windows, it is possible to include `resources' like icons, bitmaps and strings inside the executable file. For this purpose, Microsoft provides a resource compiler. The resource compiler turns the various resources into an object file which may be linked to the executable file thanks to the low-level object file linker.
Using this library, the use of resources is limited to a few basic components thanks to the library's dynamic dialogs and menu facilities which make redundant the use of resources in the most complex cases. Thus, using the resource compiler with this library is a simple task documented here, so that the user need not search the complete SDK or third-party documentation to find out the essentials. Besides, C/C++ compiler vendors sometimes bundle resource editors which generate obsfucated resource scripts in the context of full C++ application generation. The result is to obscure a task which can be handled straightforwardly by controlling the resource compilation directly.
Resources are usually stored in separate files like .ICO files for icons. These files are assembled into a linkable object file using the resource compiler, rc. The resource compiler comes with the Win32 SDK and is also distributed with the typical C compilers used to compile the output of most Eiffel compilers. If the C compiler does not use the same low-level object file as rc, a similar utility or converter should be provided with the compiler package.
The resource compiler takes a resource definition .RC file to define which resources are to be included. This script also includes some of the actual resources, like string resources.
Although the compilation could be done before low-level linking every time the Eiffel compiler builds a program, it is more sensible to have it done only when resources have been modified. This can be controlled by either the Eiffel compiler if possible, or a trivial make file, or manually after changes to the resources. The resulting object file must be mentioned on the Eiffel side, so that it is linked into the executable.
The rc program takes the resource script as its argument. Some useful command line option are: `-fo' followed by a file name for changing the output object file name -- the default is the name of the script file with the .RC extension changed to .RES Though despite the name it is a plain Win32 object file whose extension is usually .OBJ. -- and `-v' for detailed messages on the progress of the compilation.
The resource script itself includes statements for inclusion of various resource type which are described in the next section. A resource can include preprocessor statements compatible with C (#include, #ifdef, etc) although it is not very useful in our context, unless conditional processing is needed for instance. A script can contain C or C++ style comments (respectively /* comment */ and // comment to the end of line).
The preprocessor facility can be used to include files (indeed any normal C include file), which is ordinarily used among other things to get resources identifiers. Most resources identifiers used with this library (apart from string identifiers) will be strings instead of numeric identifiers. Identifiers can be specified directly in the script.
Like in C, strings including a backward slash -- often found in the name of a file or directory -- have to be included between double quotes and the backward slashes doubled.
Most resource definition statements include the resource identifier, a name or number -- usually a name, that is a string beginning with a letter -- followed by a keyword describing the resource type and then a description of the resource, such as a file name or the string itself in the case of string resources. The resources described below are useful with this library.
The keyword BITMAP is for bitmap resources, stored in standard windows raster picture files, with the .BMP extension. Many image editors can handle these files. From Eiffel, they can be used with the class BITMAP_DEVICE.
Example: applogo BITMAP logo.bmp // logo.bmp identified as applogo.
Icon resources are very similar to bitmaps, with some limitations. The keyword is ICON. They are contained in an .ICO file, which can have several icons for various resolutions or sizes -- the system will extrapolate an icon from the nearest one if the needed resolution or size is not available. The Eiffel class to load them is ICON.
Example: myicon ICON "c:\\resources\\icon.ico"
The shape of the mouse cursor can be changed with the class MOUSE_CURSOR which loads CURSOR resources. Like icons the mouse shapes are a special kind of bitmap which are edited with a specialised icon or cursor image editor. Cursor shapes are stored in .CUR files.
Example: newcursor CURSOR cursor.cur
Strings are, unlike previous resources, stored together in a string table. It contains a set of strings and associated numeric identifiers, which can be plain numbers or preprocessor symbols. The syntax is shown below. String resources are loaded from the class F_SYSTEM.
STRINGTABLE BEGIN stringID string ... END
#define ASTRING 25 STRINGTABLE BEGIN 12, "Hello world" 34, "Invalid language" ASTRING, "Mi salutas la mondon" END