Compiling Resource Scripts


To compile a resource script, you need a stone-age tool called a resource compiler. Historians tell us that Visual Basic compilers used to be invoked from command lines in a manner not unlike that required for the resource compiler, RC.EXE. Now, don’t get me wrong. I’m a command-line kind of guy. I use a Windows command-line session the way most people use the Windows Explorer. But resource files are like hot dogs: you don’t really want to know where they came from.


Unfortunately, you must handle every step of the resource process by hand, starting with the setup.


Your goal in using the resource compiler is to create a separate RES file for each target language. A batch file such as the one shown here creates them:

@echo off
Rem Make US
rc /v /d US /r /fo tresus.res tres.rc
Rem Make Swinish
rc /v /d SW /r /fo tressw.res tres.rc
If “%1”==”” Goto Done
Rem Make version specific if country (US or SW) given on command line
If exist tres%1.res Copy tres%1.res tres.res
:Done

If you change from the American version to the Swinish version from the batch file while TRES.VBP is loaded, your program will change its behavior without changing a character of source code. This feature is nice, but the process of using it can only be described as crude. You can probably think of additional pa­rameters to further define the behavior of the batch file, or, if you have a make utility, you can replace the batch file with a make file.


But whatever hacks you use, they shouldn’t be necessary. In fact, the whole process is fundamentally flawed. The RC file, not the RES file, should be part of your project. You should be able to edit it in the Visual Basic IDE. Visual Basic should automatically compile it to a RES file whenever the RC file is newer than the RES file. And that’s just the trivial implementation. If Visual Basic is going to compete with the new Rapid Application Development tools for Java and Delphi, it’s going to need an integrated resource editor. Even user-hostile languages like C++ make resource management easier.


Hmmm. You’ve seen the simple and consistent format of resource scripts. You’ve seen the mechanical process of compiling them. You have a computer. You know a computer language. You’re hardcore. All the elements are present for solving this problem once and for all.


Imagine the Resource Shop, a resource editor created specifically for Visual Basic. You could create new resources by selecting a resource type in a list box and clicking a New Resource button. You’d have a choice of inserting an existing resource from a file or creating a new one. Each resource type would have its own file editor, which you’d define when you created a new resource type. For example, you could run ImagEdit for icons, cursors, and bitmaps, or you could integrate your own more powerful editor. You’d also need editors for meta­files, wave files, strings, and hexadecimal data. You could scroll through existing resources for a project and edit any you wanted to change. Then you’d click a Save button to invoke an invisible resource compiler to compile your invisible resource script and generate a module containing Visual Basic constants for each ID. You could integrate this wonderful tool into the Visual Basic IDE as an
add-in.


Hold that thought while we examine resources more carefully from the inside out.