Types of Resources
For your Windows 98 applications, the following resources are available:
-
Images Three types of image resources are supported as bitmaps (.BMP), cursors (.CUR), and icons (.ICO). Each of these are bit images, but different rules and organizations are applied to create each one. You can edit image resources with a bitmap editor. The three bit-image resource types are discussed in Chapter 8.
On the Use of Resources
Because my tech reviewer has raised a few important questions concerning limitations on resources (there really aren’t any), I’m repeating the questions here with approximate answers.
Q:How much free memory can be used for resources?
A:All of it. In theory, the only limitation—under any 32-bit version of Windows—is the 4GB limit on addressable memory. Remember, that the operating system uses roughly 12MB of RAM, but the swap file acts as an extension to system RAM. Therefore, on a 16MB system, somewhere in the neighborhood of 20MB–30MB of RAM are available for resources. How much you use is entirely up to your application design. (And, yes, you could use a 2GB or 3GB hard drive as a dedicated swap file—why not, they’re cheap now and relatively fast if you really need that much space.)
Q:List everything that is considered a resource.
A:List everything that isn’t provided directly by your C/C++ source code. A resource—in addition to bitmaps, icons, toolbars, dialog templates, hotkey accelerators, string tables, and custom cursors—may include data objects, such as a database template, custom controls, default registry data, sound files (but these are usually external), or anything else you desire to include as a custom resource.
Q:How time-consuming is it to load and unload resources?
A:In actual fact, it isn’t. Resources are part of the application’s .EXE file (or .DLL library) and are loaded at the same time the executable runs. If there is insufficient free memory, some part of the executable or DLL is transferred to the swap file. This task is handled by Windows on a demand basis such that currently unneeded elements are off-loaded to a disk image of RAM and are recalled (moved back into active memory) when needed. In effect, there is no real way to say what the time constraints are except to observe that fast hard drives are more responsive than slow ones.
Q:Besides memory, what are the limitations on how many resources can be loaded at one time?
A:For all practical purposes, memory aside, there are none.
-
Toolbars These resources are specialized bitmap images consisting of one or more individual button images. By default, each button is 16x15 pixels, but you can size buttons as desired. (While toolbars are bitmap images, most resource editors provide a toolbar editor for greater convenience.) Toolbar resources are discussed in Chapter 8.
-
Dialog boxes These resources are generally message or input windows, but they may also be child windows used to organize a display. A dialog box editor provides an interactive means of constructing dialog boxes and showing the elements (list boxes, buttons, edit boxes, scrollbars, and so on) exactly as these will appear on screen. Dialog boxes are discussed in Chapter 9.
-
Menus These resources provide lists of program options. The options may immediately execute commands, display submenus, or display dialog boxes for other operations. A menu editor allows you to define and test main and pull-down menus. You can also create menu resources using any plain-text editor (Windows Notepad, for example). Menus are discussed in Chapter 10.
-
Accelerators These are keyboard resources. An accelerator resource is a key or key combination provided as an alternative to an individual menu item to invoke a command. One common example is pressing the Shift+Ins or Ctrl+V combinations as an alternative to pulling down the Edit menu to select the Paste option. You can define these hotkey shortcuts for menus with an accelerator editor or a plain-text editor. Accelerator resources are discussed in Chapter 11.
-
Strings These resources are text strings that are displayed by an application in its menus or dialog boxes, for error messages or other information. By defining text strings as resources, rather than embedding them in the source code, you can conserve memory. Also, keeping all message strings in a single location makes it easier to standardize message formats and to maintain consistency. Another advantage of this approach is that it allows you to edit strings for language changes without recompiling. You can create string tables using any plain-text editor or a string table editor. String resources are discussed in Chapter 11.
-
Version This resource contains information about the application, such as its version number, its intended operating system, and its original filename. It is intended for use with the File Installation library functions. Version resources are discussed in Chapter 11.
While application resources are, nominally, contained in the .RES resource script file during development, binary resource objects—such as bitmaps, cursors, and icons among others—are stored separately as individual files. Also, several custom file types can be used to store individual resource objects separate from the resource script.
© 1998 SYBEX Inc. All rights reserved.