Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 3: Windows Resources Visual C++ and MFC Fundamentals


3.1 Introduction to Resources


3.1.1 Introduction..............................................................................................


A resource is a text file that allows the compiler to manage such objects as pictures,
sounds, mouse cursors, dialog boxes, etc. Microsoft Visual C++ makes creating a
resource file particularly easy by providing the necessary tools in the same environment
used to program, meaning you usually do not have to use an external application to create
or configure a resource file.

Although an application can use various resources that behave independently of each
other, these resources are grouped into a text file that has the .rcextension. You can create
this file manually and fill out all necessary parts but it is advantageous to let Visual C++
created it for you. To do this, you add or create one resource at a time when designing it.
After saving a resource, it is automatically added to the .rc file. To make your resource
recognizable to the other files of the program, you must also create a header file usually
called resource.h. This header file must provide a constant integer that identifies each
resource and makes it available to any part that needs it. This also means that most, if not
all, of your resources will be represented by an identifier.

Because resources are different entities, they are created one at a time. They can also be
imported from existing files. Most resources are created by selecting the desired one from
the Add Resource dialog box:

Figure 44: Add Resource - Icon...................................................................................................


The Add Resource dialog box provides an extensive list of resources to accommodate
almost any need. Still, if you do not see a resource you need and know you can use it, you
can add it manually to the .rc file before executing the program.
Free download pdf