Introduction and a bare-bones PM application (Resources)

Written by Gavin Baker

Introduction
Menus, dialog boxes and icons are all examples of Resources in OS/2. Resources are stored in their own read-only segment within the executable file (or DLL), can be shared between multiple instances of a program, and are normally loaded only when required at runtime rather than at the load time of the application.

The most commonly used resource types along with their definition are shown below: Resources are created in two ways (depending on the type of resource). They are either text or binary. The binary resources are POINTER, BITMAP, and FONT. All the other resources are textual. The RCDATA type is special, as it allows the programmer to define a custom structure for a resource.

The RC.EXE program is called the Resource Compiler, and it takes the your source file and compiles it into a binary form (.RES). It also binds the .RES file with your executable.

We will examine the general syntax of resources and the structure of the RC file, and then examine each type in detail.

Scope
I am assuming that you are a competent C programmer, and have a working knowledge of OS/2 from a user's perspective. The sample code here was produced with Borland's Resource Workshop for PM and tested with the OS/2 Resource Compiler (RC).

Syntax and the RC File
Resources are defined in a text file with the .RC extension. There are a number of keywords for the different resource types, and each keyword defines one resource. Resources are referenced by an identifier, which takes the form of a C #define. Since the Resource Compiler (RC.EXE) supports C-like #includes and #defines, it is convenient to have all the symbols defined in one header file for the resources and their IDs. (Obviously they must have unique numbers). Resources are usually named according to a certain convention - ID followed by a single letter denoting the resource type, an underscore and then a descriptive name. Here are some examples: Generally speaking, a resource statement consists of the following: Due to the differing nature of resources, it is easier to show the syntax for each type's definition rather than to generalize here.

The options refer to the Memory Options, which specify how OS/2 treats the memory occupied by the resource. The memory options are as follows: Note that the default options are marked with an asterisk. These options apply to all of the resource types.

Resources
In the following sections we will see each type of resource (at least the most common ones) and some examples, along with how to use them in your programs.

The syntax diagrams follow those conventions used in the Command Reference, but also note that keywords are underlined.

Output
There is no output as such from this resource - you would use it in your program like this: This will load an error message from the executable file and display an error message in a box.

Syntax
The dialog template itself: The Control Definition:

Example
This example was produced with Borland's Resource Workshop for PM (part of Borland C++ for OS/2), which makes it easy to visually design dialogs and other resources. The IBM Toolkit also includes a Dialog Editor.

As you can see, a reasonably simple dialog can get fairly complex. If you were to write this by hand it would take hours to figure out the X and Y positions, flags, etc. This is not practical for anything but the simplest of dialogs, so a dialog editor (such as the two mentioned above) is invaluable.

This may seem complicated, but it is fairly straightforward. Everything except the buttons is defined as a CONTROL (a generic way of specifying a control). The type of control is given in the flags, for example the comment edit field is defined as a WC_ENTRYFIELD, and has its own specific flags (ES_LEFT and the others). There are lots of flags specified (more than if you had done it by hand) but most have reasonable defaults.

Three things to note:
 * The order is important - it is the order the user tabs through in.
 * The WS_TABSTOP flag must be specified if you want the user to be able to tab to the control under keyboard control.
 * Groups (WS_GROUP) are mainly used to group together automatic radio buttons, so they turn each other off and on.

Output


Roundup
Well, there you have Resources in a nutshell. You will find that tools such as Borland's Resource Workshop and those included with IBM's Toolkit can save you from ever having to understand all that we have just discussed, as you can point and click and the work is done for you.

However, it is very useful to know just how resources are created as it gives you a better understanding of just what you are doing.

Now for those of you who have eagerly gone to consult your manuals (or the header files for that matter), you will have noticed that I left out a few resource types. I did this to save both time and space, and also because they are infrequently used. I won't dare say that it is left as an exercise for the reader, but if there is enough demand I will cover the remaining types in a later article.

What Next?
Next we look at the Graphics Programming Interface (GPI).

I would love to hear from you about what you thought, how useful it was, whether or not there was too much or not enough information, if it was too wordy or too simple - in short any and all comments are most welcome. Also, if there is something specific you would like to see covered, drop me a line too.