A Preview of the Resource Editors

Now that you have a complete application program, it's a good time for a quick look at the resource editors. Although the application's resource script, ex03a.rc, is an ASCII file, modifying it with a text editor is not a good idea. That's the resourc葝2*5E}cE葝2*5E45">

The Contents of ex03a.rc

The resource file determines much of the EX03A application's "look and feel." The file ex03a.rc contains (or points to) the Windows resources listed here.

AcceleratorDefinitions for keys that simulate menu and toolbar selections.
DialogLayout and contents of dialog boxes. EX03A has only the About dialog box.
IconIcons (16-by-16-pixel and 32-by-32-pixel versions), such as the application icon you see in Microsoft Windows Explorer and in the application's About dialog box. EX03A uses the MFC logo for its application icon.
MenuThe application's top-level menu and associated pop-up menus.
String tableStrings that are not part of the C++ source code.
ToolbarThe row of buttons immediately below the menu.
VersionProgram description, version number, language, and so on.

In addition to the resources listed above, ex03a.rc contains the statements

#include  "afxres.h"
#include  "afxres.rc"

which bring in some MFC library resources common to all applications. These resources include strings, graphical buttons, and elements needed for printing and OLE.

If you're using the shared DLL version of the MFC library, the common resources are stored inside the MFC DLL.

The ex03a.rc file also contains the statement

#include  "resource.h"

This statement brings in the application's three #define constants, which are IDR_MAINFRAME (identifying the menu, icon, string list, and accelerator table), IDR_EX03ATYPE (identifying the default document icon, which we won't use in this program), and IDD_ABOUTBOX (identifying the About dialog box). This same resource.h file is included indirectly by the application's source code files. If you use a resource editor to add more constants (symbols), the definitions ultimately show up in resource.h. Be careful if you edit this file in text mode because your changes might be removed the next time you use a resource editor.

Running the Dialog Resource Editor

  1. Open the project's RC file. Click the ResourceView button in the Workspace window. If you expand each item, you will see the following in the resource editor window.

  2. Examine the application's resources. Now take some time to explore the individual resources. When you select a resource by double-clicking on it, another window opens with tools appropriate for the selected resource. If you open a dialog resource, the control palette should appear. If it doesn't, right-click inside any toolbar, and then check Controls.

  3. Modify the IDD_ABOUTBOX dialog box. Make some changes to the About Ex03a dialog box, shown here.

  4. You can change the size of the window by dragging the right and bottom borders, move the OK button, change the text, and so forth. Simply click on an element to select it, and then right-click to change its properties.

  5. Rebuild the project with the modified resource file. In Visual C++, choose Build Ex03a.exe from the Build menu. Notice that no actual C++ recompilation is necessary. Visual C++ saves the edited resource file, and then the Resource Compiler (rc.exe) processes ex03a.rc to produce a compiled version, ex03a.res, which is fed to the linker. The linker runs quickly because it can link the project incrementally.
  6. Test the new version of the application. Run the EX03A program again, and then choose About from the application's Help menu to confirm that your dialog box was changed as expected.