Visual C++ Development Environment: About This Chapter
Visual C++ Development Environment: About This Chapter
Chapter 2
Visual C++ Development Environment
About This Chapter
In this chapter, you will learn about the development environment and the tools that enable you to create
applications using Microsoft Visual C++. You will learn how to use the MFC AppWizard to generate a
development project, which contains source code and resource files that you can compile into a working
executable program. You will explore features of the Visual C++ development environment, and learn
how to configure options for your project. You will also learn how to use Microsoft Visual SourceSafe
to manage source code control for a software development team.
To complete the lessons in this chapter you must have installed the Visual C++ development tools as
described in Lesson 2 of Chapter 1.
Describe the types of projects you can create with the AppWizard.
Understand the steps involved in using the AppWizard to create an MFC executable
application.
In a Visual C++ project, settings for the build tools such as the compiler, resource compiler, and linker
are centrally controlled through the Project Settings dialog box. You can specify any number of
independent configurations of settings for your project. When you use the AppWizard to create a
project, both Debug and Release configurations are created for you automatically.
Projects are always contained within a workspace. By default, a single project will be created inside a
workspace, and both configurations will have the same name. To organize your development more
effectively, you can group related projects together into a single workspace. You can also set
dependency relationships between them to ensure build consistency between projects that share files.
Although your workspace might contain more than one project, you work on only one project at a time,
known as the active project. Figure 2.1 is an illustration of a workspace that includes three projects.
Note that the active project is displayed in bold type.
Start Visual C++ by clicking Start, pointing to Programs, pointing to Microsoft Visual C++ 6.0, and
then clicking Visual C++. On the File menu, click New.
You use the New command to create new workspaces, projects, source files, or resource files. You can
also create blank documents for other Microsoft applications such as Microsoft Word or Microsoft
Excel.
The Visual C++ New Project dialog box gives you the option of creating a project for the development
of applications, components, or libraries using the following methods:
MFC development The MFC development option generates a framework based on MFC, which
you can use to develop applications, DLLs, or ActiveX controls. Other project types, such as those
generated by the Internet Server API (ISAPI) Extension Wizard, are also based on an MFC
framework.
Although MFC saves you time and effort in the creation of Windows programs, simple programs
might not justify the code size and performance overhead of MFC. To use MFC in an application,
you need to link the MFC static libraries to your code or ensure that the MFC DLLs are installed
on each computer that will run your application. Consider whether your application needs the
types of application framework created by the MFC project options.
Win32 development The Win32 options allow you to create simple Windows-based programs
without the overhead of MFC. You can choose to create an empty project configured with the
appropriate settings for generating Windows programs, which allows you to start developing a
Windows application from scratch. Alternatively, you may choose to have the wizard implement
the basic architecture of a Windows application. The wizard will handle basic tasks such as
registering your window classes, setting up a message loop to process user input to the program,
and implementing a basic window procedure to perform actions based on messages generated by
the user input. You also have an option to create a Windows DLL. Here, too, you may create a
completely empty project or create a project with sample code that shows you how to export
classes, functions, and variables from a DLL. You can also choose to create a simple console
application that will run without a graphical user interface from the command prompt, or choose
an option to create a static library for linking to an executable program at build time. These
options allow you to include support for MFC, which you might do if you want to take advantage
of the MFC string or collection classes.
ATL development The ActiveX Template Library (ATL) is a set of template-based C++ classes
that helps you create small, fast COM objects. We will be covering ATL in depth in Chapters 9
through 11. The ATL COM AppWizard allows you to create a COM server, a DLL, or an .exe file
that can host COM components. Once you have used the wizard to create your ATL project, you
can add a number of different types of ATL-based COM objects. These can include simple COM
objects, objects that can be used with Microsoft Transaction Services or in Active Server Pages,
Microsoft Management Console SnapIns, ActiveX user-interface controls, and OLE DB data
providers and consumers. Other project types, such as those generated by the DevStudio Add-in
Wizard, are also based on ATL templates.
Miscellaneous projects A number of C++ development options do not fall into the above
categories. These include options that allow you to create DLL resources to run on Microsoft
Internet Information Server (IIS) or on Microsoft Cluster Server. You can also write your own
Visual Studio add-ins, create general-purpose utility projects, and develop your own custom
AppWizards.
NOTE
The Enterprise edition of Visual C++ contains some project options not found in the
Standard or Professional editions. These allow you to work with DEFINTION (ODBC)
databases directly from Visual Studio and to create SQL Server extended stored procedures.
NOTE
AppWizard will create your project in the default location in the directory: C:\Program
Files\Microsoft Visual Studio\MyProjects. If you want, you can enter a different location in
the Location edit box.
The first dialog box of the MFC AppWizard, shown in Figure 2.3, appears.
Step 1 of the MFC AppWizard gives you the option to choose whether your project is to produce a
single-document interface (SDI) application (the Single document option); a multiple-document
interface (MDI) application (the Multiple documents option); or an application that is based around a
dialog box (Dialog based option). SDI applications permit only one document, displayed within the
application's main window, to be open at a time. MDI applications allow multiple documents, displayed
in multiple child windows, to be opened within a single instance of an application. Dialog-based
applications use a dialog box as their main application window rather than the style of window that
displays a client area inside a frame. Lesson 4 in Chapter 3 discusses these application types in more
detail.
You can get help on any of the options in the AppWizard by selecting the appropriate option and
pressing F1.
The following steps show you how to make MyApp.exe an SDI application.
1. Change the application type option from Multiple documents to Single document. Click Next to
proceed to the next dialog box (shown in Figure 2.4).
2. A discussion of MFC database support can be found in Chapter 7, Adding Database Support.
Leave None selected and click Next to proceed to the next dialog box (shown in Figure 2.5).
3. This dialog box presents you with options associated with ActiveX technologies. ActiveX
technologies use COM to enable software components to interact with one another, regardless of
the language in which they were created. OLE is another COM-based technology used for
creating and working with compound documents—documents that can contain data of different
formats, created by different applications. We cover COM and the ActiveX technologies in depth
in Chapters 8 through 12. Leave the default options selected, and click Next to move to Step 4
(shown in Figure 2.6).
4. The AppWizard options presented allow you to specify the features your application will support.
Leave the default options selected and click Advanced.
5. The Advanced Options dialog box has two tabs. The Document Template Strings tab (shown in
Figure 2.7) allows you to set options for the document type associated with your application. This
is useful so that Windows can associate a document type with an application. A user can then
double-click a filename and have Windows automatically start the application appropriate for
using that file. The Window Styles tab (shown in Figure 2.8) provides settings that allow you to
specify display characteristics of the application window.
Figure 2.7 The Document Template Strings tab of the Advanced Options dialog box
Figure 2.8 The Window Styles tab of the Advanced Options dialog box
6. On the Document Template Strings tab, type mya in the File extension box and click Close.
Click Next to move to the next dialog box (shown in Figure 2.9).
7. The first option on this dialog box allows you to create an application with an interface similar to
that provided by Windows Explorer—essentially a tree control view and a list control view side
by side in a split window. Leave MFC Standard selected. Leave the second option set to the
default. The last option deals with how the MFC Libraries are to be distributed with your
application. Leave the As a shared DLL option selected, and click Next to continue to proceed to
the final AppWizard dialog box, shown in Figure 2.10.
8. The final AppWizard dialog box (shown in Figure 2.10) provides information about the classes
and files that will be created for you. You can change the automatically generated names if you
are not happy with the defaults. Notably, it allows you to change the base class from which your
view class is derived. The view class is used in an MFC application to display the application
data. Click the Base class drop-down list to see the options available.
Powerful features are available from this drop-down list. Many of the base classes listed
incorporate functionality based on Windows common controls, which you can use to help you
organize the display of your application data. If you select CRichEditView, you can construct an
application based on a full-featured text editor. With CHtmlView, your application would be
based on an HTML browser. The default CView provides your application with a blank window
where you can display your application data in any form you choose. CScrollView is similar to
CView, but it creates a scrollable view that enables you to display more data than can be shown in
a single screen window.
9. In the Base Class, click CScrollView. Click Finish to proceed to the New Project Information
dialog box. The AppWizard presents a summary of the project so that you can double-check the
selections you've specified. The AppWizard cannot be rerun (against the same project) once the
project has been generated. For this lesson, simply read the summary and click OK. The project is
created and opened for you in a new workspace.
10. The MyApp Classes icon will appear in the Workspace window. Click the icon's plus sign to
view the classes that the AppWizard has created. In the next lesson, you will compile these classes
into a working application. Double-click the CMyAppApp Class icon to view the source code for
the class declaration.
Lesson Summary
The source code and resource files that make up an application or component are grouped together in
projects. Projects enable you to easily manage your files and build settings. You can specify any number
of independent configurations of settings for your project. Related projects may be grouped together into
a single workspace.
Visual C++ provides a number of project wizards that provide frameworks from which you can develop
different types of applications and components, using a variety of technologies.
The MFC AppWizard allows you to quickly and easily create a set of classes and resources that can be
compiled to produce a complete MFC executable application. By using the AppWizard you can:
Choose from a number of specialized base classes for your application view.
In this lesson, you will examine some of the features of the Visual C++ development environment
typically used in the course of developing applications.
Understand the elements of the Visual C++ user interface, including its windows,
menus, and toolbars, and how they can be configured and customized.
The workspace window uses hierarchical tree controls to display a graphical view of the objects in your
workspace. As you saw in Lesson 1, the projects in the workspace form the root items of this hierarchy.
The workspace window offers three different views of the contents of your project, which are accessed
by the three tabs along the bottom of the window:
ClassView Presents an object-oriented view in terms of the C++ classes, their data members, and
their member functions. Double-clicking any of these objects will take you directly to their
definition or implementation in the source code.
ResourceView Displays resource objects grouped by category. Double-clicking any object will
load the appropriate editor.
Right-clicking an object in any of the views will bring up a shortcut menu with a set of object-related
options.
The edit window is the area in which you work on open files, either with the program editor or one of
the resource editors. If you would like more space while editing, click the Full Screen command on the
View menu.
A new installation of Visual C++ shows the three most commonly used toolbars. The Standard toolbar,
which contains the most frequently used commands for working with files; the Build MiniBar, which
contains the most frequently used commands for building and running applications; and the WizardBar,
which provides commands for working with classes.
Right-clicking an empty area of any of the toolbars or the main window frame will show you a list of
available toolbars and will allow you to toggle their display status on or off.
The following exercises will demonstrate how you can customize your user interface and will provide
you with a means to turn a full-screen edit window on or off with a single mouse click or keystroke.
1. From the Tools menu, choose Customize. The Customize dialog box appears.
4. Click the Full Screen icon (the third from the left in the top row of icons), and note that a
description of the command appears below the Category drop-down list. The dialog box should
now look like the one shown in Figure 2.12.
8. Test your new button by clicking it to show the source file in full-screen mode. When you want to
switch back from full-screen, click the button again.
NOTE
While the Customize dialog box is open, you can delete buttons from toolbars by right-
clicking them and choosing Delete from the shortcut menu. You can also delete buttons by
simply dragging them off the toolbar you want to remove them from and dropping them
anywhere but on another toolbar.
1. On the Tools menu, click Customize. The Customize dialog box appears.
4. In the Commands box, click ToggleFullScreen. Note that a description of the command appears
5. Click in the Press new shortcut key edit control, and then press PAUSE on your keyboard.
6. Click Assign. The dialog box should now appear as it is shown in Figure 2.13.
8. Test the effect of pressing PAUSE. Your edit window should switch back and forth between
window mode and full-screen mode.
Aspects of the code editor, from basics such as window settings and save options, to advanced
features such as automatic code completion and colored syntax highlighting. The editor can even
be configured to emulate other popular editors such as BRIEF.
The directory paths to search when loading executable files and when looking for source files,
include files, and library files.
Getting Help
Visual Studio 6.0 ships with its own release of the Microsoft Developer Network (MSDN) library. This
is an essential reference for developers, containing more than a gigabyte of technical programming
information, including documentation, technical articles, sample code, the Microsoft Knowledge Base,
and anything else you might need to develop solutions using Microsoft technology.
The MSDN library runs in its own HTML-based environment, complete with a fast, intelligent search
engine. It is integrated with the Visual C++ development environment so that context-sensitive help is
always available from within the Text editor (and from the output windows) simply by pressing F1.
Microsoft has provided further assistance in the form of context-sensitive Automatic Statement
Completion. This feature, also known as IntelliSense, puts the MFC, Win32, and ATL libraries at your
fingertips by displaying class members, function prototypes, identifier declarations, and code comments
at the insertion point while you're editing your code. IntelliSense instantly shows all the available
options. IntelliSense also optionally completes recognized words for you, saving you from continually
Changes made to any settings on any of the tabbed pages apply only to the currently selected project and
the build version specified in the Settings For list. Each build type of each project has its own
combination of settings. To maintain the same settings for all build versions of a project, select All
Configurations in the Settings For list. When changing project settings, be careful to check the build
version you are modifying. It is easy to apply settings to the wrong build version if you aren't careful.
1. On the Project menu, click Settings. The Project Settings dialog box appears.
4. In the Settings For box, click All Configurations. Note that now only the settings common to all
configurations are displayed in the Common Options box on the property sheet.
5. Select Enable Run-Time Type Information (RTTI) to make RTTI available for all
configurations of the MyApp project. Note how the /GR compiler switch is added to the Common
Options box.
6. Click OK to close the Project Settings dialog box and save your changes.
When editing settings at the project level, the current project should be selected in the tree view in the
left pane. You can move through the project's category folders and the individual files in the category
folders. The settings available to you on the property sheets in the dialog box will correspond to the
object that you selected in the tree. A common setting that occurs at file or folder level is the exclusion
of a particular file, or set of files, from a build.
The Debug, C/C++, and Link tabs actually contain several pages of settings within a single page. To
switch between these different groups of settings, select one of the options from the Category list on
each page.
Some of the options you can set using the Project Settings dialog box are:
General Settings Here you can specify whether to link your executable program with the static
MFC libraries (in case you change your mind after specifying this in Step 5 of the AppWizard).
You can also specify directories for your output files.
Debug Settings Here you can pass command-line arguments to your program when it is started in
the debugger. You can also use I/O redirection as you would from the command prompt.
C/C++ Settings Here you can set general compiler settings, language features, calling
conventions, processor-dependent settings, optimizations, preprocessor definitions, and so on.
Linker Settings Here you can specify additional libraries to link to your executable program.
Building a Project
Now that you have a better understanding of the working environment, you are going to build the
MyApp application from the project you created in Lesson 1.
To build MyApp.exe
1. On the Build menu, click Set Active Configuration. Ensure that MyApp—Win32 Debug is
selected and click OK.
TIP
When you are working with multiple projects and configurations, consider using the full
Build toolbar rather than the Build MiniBar. The Build toolbar contains drop-down list box
controls that allow you to switch between projects or configurations quickly and easily.
These controls also remind you which project or configuration you are currently working
on.
or
or
Press F7.
The program will compile and link, and the MyApp.exe file will be generated in the Debug directory.
or
On the Build MiniBar, click the Execute Program button (the red exclamation mark that is two
buttons to the right of the Build button)
or
Press CTRL+F5.
Notice that the output window appears at the bottom of the screen. The output window contains a
number of views that are accessible by clicking the tabs at the bottom. The appropriate view is
generally displayed automatically according to what kind of output is being generated by the
environment. As the build process runs, the Build tab displays messages from the compiler and
linker.
2. Once the build process has completed, test the functionality that has been provided for free by the
AppWizard. On the File menu, click Open to see how a standard file dialog box is opened for
you. You will need to implement File Open and Save routines yourself.
3. On the File menu, click Print Preview and see how the Print Preview architecture is already in
place. Code that you add to display output in your application main window will also display in
this Print Preview window, formatted as it would appear on printed pages.
4. Click Close to close the Print Preview window, and choose Exit from the File menu to close the
MyApp application.
Lesson Summary
Visual Studio 6.0 provides a rich, visual environment for developers, known as the integrated
development environment, or IDE.
A new installation of Visual C++ will arrange a project for you. Along with the menus and toolbars, the
user interface is organized into three main areas: the workspace window, the edit window, and the
output window. The workspace window offers three different views of the contents of your project.
ClassView presents an object-oriented view in terms of the C++ classes, their data members, and their
member functions. ResourceView displays resource objects grouped by category. FileView presents a
view of all the editable files in your project.
Visual C++ provides a wide range of toolbars that you can hide, show, and configure according to your
needs. You can configure toolbars using the Customize command on the Tools menu.
Visual C++ provides a fully configurable environment. You can configure the environmental options for
your installation of Visual C++ using the Options command on the Tools menu.
Visual Studio 6.0 ships with its own release of the MSDN library, an essential reference for developers.
Visual C++ provides a central location for configuring project settings. You can use the Project
Settings dialog box to configure the options for the compilers and the linker used by Visual C++. You
can specify any number of different configurations of project settings.
In this lesson, you will learn how to set up a source code control system using Microsoft Visual
SourceSafe (VSS) 6.0, which comes as a part of Visual Studio 6.0, and you will use the features of
Visual SourceSafe from within the Visual C++ development environment.
Describe how to use the Visual SourceSafe Administrator to set up a new database,
add a user, and maintain passwords.
Describe how to place a Visual C++ development project under source code control.
Describe how the integrated source code control features of Visual C++ simplify the
tasks of maintaining source code control for the developer.
files, sound files, and video files, can be stored under source control. When you add a file to VSS, the
file is stored in the database and made available to other people. Members of your team can see the latest
version of any file, make changes, and save a new version in the database. Changes that have been made
to the file are saved so that you can recover an old version at any time.
As a developer of a source code control system, you will keep a read-only copy of the source files in a
working folder on your local hard drive. When you want to modify a file, you check out the file from the
VSS database. This places an editable copy of the file in your working folder and prevents other users
from overwriting the current versions. When you have finished making changes, you check in the file to
make your newly edited version the latest version that is available to the other developers. If you want to
abandon the changes that you have made, you can undo the check out, thereby replacing your local
edited version with the previous copy of the file held in the database.
To make sure that you have the latest version of all the files in the project, you use the Get Latest
Version command to copy the current versions of the project source files to your working folder.
By default, a user cannot check out a file that is already checked out to another. This ensures that only
one person at a time is modifying a file. Suppose that developer A and developer B are allowed to work
on the same file at the same time. If A saves his changes, and subsequently B saves hers, all the changes
made by A will be lost. The VSS administrator can change the default setting to allow multiple
simultaneous checkouts of a single file and prevent overwrites of other changes. This will require some
extra work on the part of the administrator, who must use the VSS Merge facility to ensure that the
simultaneous changes do not conflict.
When you check out a source code file for editing, you must always be sure that you have the latest
version of all the other files in the project. Otherwise, you might make changes that render your code
incompatible with other recently-edited modules. VSS supplies the Get Latest Version command to
copy read-only copies of source files to your working folder.
Files are organized within a VSS database in projects. A project typically contains all the files required
to develop a software component, although projects can be defined in any way that is meaningful to the
user. Projects tend to be organized in the same way as file directories.
It is usual to appoint an administrator to be responsible for the VSS database. The administrator uses the
Visual SourceSafe Administrator program to control the location of the database, maintain the user list
and access rights of each user, and back up the database.
The Visual SourceSafe Explorer is a utility that provides users with an interface to VSS projects.
However, many of the common tasks—checking files in and out, getting latest versions, and so forth—
are directly available to developers from within the Visual C++ development environment. The
integration of VSS with Visual C++ actually simplifies the process of source code control for the
developer.
NOTE
The source code control features of Visual C++ are designed to work with other products in
addition to Visual SourceSafe. Any source code control system that conforms to the
Microsoft standard source code control interface will allow you to access source code
control functionality directly from the Visual C++ menus.
4. On the Visual Studio maintenance screen, select Microsoft Visual SourceSafe 6.0. Click
Continue to install VSS.
5. When the installation is complete, close the Visual Studio setup program.
A VSS Workstation installation sets up a private VSS database on your computer and the VSS client
software. In a live team development situation, you would install the VSS Server components and create
a shared VSS database on a secure, regularly backed-up server.
1. On the Start menu, point to Programs, point to Microsoft Visual Studio 6.0, point to Microsoft
Visual SourceSafe, and click Visual SourceSafe 6.0 Admin.
2. Log on to VSS as Admin with no password. If the program warns you that the Admin account has
no password, just click OK.
3. On the Tools menu, click Create Database. The Create New VSS Database dialog box appears.
4. In the text box, type C:\Source Control\MyVSS. Leave the check box selected. Click OK to
create a new VSS database named MyVSS at the specified location and to create any necessary
directories.
2. In the Open SourceSafe Database dialog box, click Browse. Use the File dialog box to locate
and open the srcsafe.ini file in the C:\Source Control\MyVSS folder.
3. Click OK. The MyVSS database should now appear in the Open SourceSafe Database dialog
box. Make sure that it is selected and click Open.
4. Click OK.
5. Note that the name of the current database appears in the window's title bar.
3. In the Change Password dialog box, leave the Old Password box blank. Type and confirm a
new password.
2. Using the Add User dialog box, type your user name and a password. Note that you can use a
check box to specify that a user has read-only access. Leave this unselected.
3. Click OK.
2. Right-click an empty area of the main window frame. On the toolbars menu, click Source
Control.
3. The Source Control toolbar, shown in Figure 2.17, appears. Commands in the following
exercises refer to buttons on this toolbar. Alternatively, you can use the equivalent commands
from the Source Control submenu of the Project menu.
5. The Visual SourceSafe Login box appears. Make sure that MyVSS is displayed in the Database
box. Enter the user name and password that you created for yourself on the MyVSS database.
6. When you click OK, the Add To SourceSafe Project dialog box appears, displaying the MyApp
project name. Click OK (and Yes to create the new project) to add your MyApp project to source
control.
NOTE
The $/ symbol signifies the root project of the database. All projects in a VSS database are
subprojects of the root project.
7. The Add To Source Control dialog box appears with all the files in your project selected. Click
OK to add the selected files to source control.
1. Start VSS Explorer (shown in Figure 2.18) by clicking the Source Control button on the
rightmost side of the Source Control toolbar.
2. Experiment with the interface by expanding the folders in the left pane and looking at which files
have been placed in the project. Explore the menus and use the ToolTip feature to identify the
buttons on the toolbar.
3. On the SourceSafe menu, click Check Out (or use the corresponding toolbar button).
4. Click OK to check out the ReadMe.txt file. Notice how Visual SourceSafe Explorer displays the
checked-out status.
5. Switch back to Visual C++. Look at the project files in the FileView window. Notice that the file
icons are now gray to indicate that they are under source control. Notice that the ReadMe.txt file
has a check mark to indicate that it is checked out.
To check in a file
2. As an alternative to using the menu and toolbar, check in the ReadMe.txt file by right-clicking the
file and clicking Check In on the shortcut menu.
Close VSS Explorer and return to Visual C++. You might now want to try repeating the above actions
from within the Visual C++ development environment. You will find that the procedure is virtually
identical. You can use commands on the Source Control submenu of the Project menu, the Source
Control toolbar buttons, or you can right-click the icon in the FileView window.
Figure 2.19 shows the default settings for source control options. These settings will affect the way you
work with Visual C++ in the following ways:
Check out source files when edited When you attempt to edit a file that is not already checked
out to you, a Check Out dialog box will appear to allow you to check out the file. (Note that you
are prohibited from editing files that are not checked out to you.)
Prompt to add files when inserted When you add files to a project, you will be prompted to add
them to source control.
Perform background status updates The status of the files under source code control is updated
as a background task rather than immediately.
Use dialog for checkout When you check out files directly from ClassView, ResourceView, or
FileView, a dialog box appears prompting you to confirm the action. If this option is not selected,
the selected files are checked out immediately.
Include only selected files in dialogs When you elect to perform an action (such as Add to
Source Control or Check In) on selected files in ClassView, ResourceView, or FileView, only
those selected files will appear in the dialog box. Otherwise, all of the files to which the action
could be applied are listed in the dialog box.
Get files when opening the workspace When this option is set, VSS asks you if you want to get
the latest versions of all files not checked out to you when the workspace is opened. This might
not always be what you want, especially if your development is in an interim stage.
Check in files when closing the workspace When this option is set, VSS prompts you to check
in any files that are checked out to you when you close your Visual C++ workspace. Again, this
might not be a good idea if your development is still in progress. Other users might get incomplete
versions of your files.
Add new projects to source control When this option is set and you create a new project, you
will be prompted to add the new project to source control.
Clicking Advanced on this property sheet exposes a relevant subset of the source code control
program's configuration settings.
Sharing
In VSS, one file can be shared among multiple projects. Changes to the file from one project are
automatically seen by other projects sharing the same file. For example, suppose you want to share all
the header files in your MyApp project with another project. To share a file, you create a share link
between two (or more) projects. The same file then appears in those projects at the same time. When you
check in the file to any one of the projects, your changes are automatically updated in all of the linked
files.
2. To create another project with which to share files, right-click the MyApp project icon and click
the Create Project button.
3. In the Create Project dialog box, type NewProject as the project name and click OK.
6. In the Share with dialog box, click the MyApp project in the projects pane.
7. In the File to share text box, type *.h and press ENTER to display only the MyApp header files.
8. Select all the files in the list of header files displayed. (Click the first item in the list, and then
press and hold SHIFT while clicking the last item in the list.) Click Share.
9. Click Close. Note that the shared files have been added to the NewProject project and that they
have special icons to indicate their shared status.
1. Right-click one of the files with a shared file icon. From the shortcut menu, select Properties.
2. Click the Links tab on the property sheet. The projects that share this file will appear in the list
box.
Branching
Normally when you share files, only one version of the file exists. However, you might want to create a
custom copy of the file for a particular project. For example, suppose you want to create a custom
version of the MyAppDoc.h file in the NewProject project. To achieve this, you can use the VSS
branching feature. Branching duplicates files from one project and uses the duplicates to create a new
version of the project. These duplicate files can be altered without affecting the original version of the
files. At a later stage, you can use the Merge facility to merge the changes in both these versions to
recreate a single version of the file.
1. In Visual SourceSafe Explorer, click the NewProject project. In the right pane, click the
MyAppDoc.h file.
3. Click OK. Note how the file icon reverts to a non-shared type.
Merging
As mentioned above, files that have been branched into parallel versions can be merged back into one
file. For example, suppose now that your team has made changes to the original version of MyAppDoc.h
in the MyApp project, and you want to merge these changes into the custom version that is contained in
the NewProject project. Merging compares the differences between files and creates a single file
containing all the changes.
1. In the Visual SourceSafe Explorer, click the NewProject project. In the right pane, click the
MyAppDoc.h file.
3. In the Merge to $/ NewProject /MyAppDoc.h dialog box, select the MyApp project. Note how
the versions that are to be merged are displayed in the Versions column. Click Merge, and then
click OK in the message box that follows.
Merging might commonly take place when the administrator enables multiple checkouts of the same file
to allow parallel development to take place on a single source file. Users can also merge the differences
between an existing local copy of a file and the most up-to-date version saved in the VSS database by
using the Get Latest Version command.
1. In the Visual SourceSafe Explorer, click the NewProject project. In the right pane, click the
MyAppDoc.h file.
3. Click OK to accept the default options. The file's version history is displayed.
1. Open the VSS Administrator program. You should be taken directly to the MyVSS database you
created earlier.
3. In the Choose Project to Archive dialog box, select the MyApp project and click OK.
4. With the MyApp project displayed in the Archive Wizard Projects to archive box, click Next.
5. In Step 2 of the Archive Wizard, select the Save data to file option and specify
C:\SourceControl\backup.ssa as an archive file name. Click Next.
6. In Step 3 of the Archive Wizard, select Archive all of the data and click Finish.
7. When the archive process is complete, close the VSS Administrator program.
To restore from an archive, simply open the database you want to restore to from within the VSS
Administrator program. Choose Restore Projects from the Archive menu, and use the Restore Wizard
to locate and load the .ssa file that contains the archive.
Lesson Summary
Source code control provides the ability to track changes made to source code files and is an important
part of team software development. Visual SourceSafe (VSS) 6.0, which comes as a part of Visual
Studio 6.0, is a source code control system that is fully integrated with the Visual C++ development
environment.
VSS stores a central copy of your source code files in a database. Members of your team can see the
latest version of any file, make changes, and save a new version in the database. Changes that have been
made to the file are saved so that you can recover an old version at any time.
Users of a source code control system keep a read-only copy of the source files in a working folder on
their local hard drive. When you want to modify files, you can use the Visual SourceSafe Explorer
program to check out the file from the VSS database. This places an editable copy of the file in your
working folder. When you have finished making changes, you check in the file to make your newly
edited version the latest version that is available to the other developers. To make sure that you have the
latest version of all the files in the project, you use the Get Latest Version command to copy the current
versions of the project source files to your working folder.
The VSS Administrator Program allows you to set up and administer a VSS project for your
development team. You can use this program to control access to the VSS database and to archive and
restore projects.
Visual SourceSafe is fully integrated with the Visual C++ development environment. Visual C++ can be
configured to perform many of the source code control tasks automatically—for example, you can
configure the environment so that when you add files to a Visual C++ project, you will be prompted to
add them to source control.
The Visual SourceSafe Share command allows you to share a single copy of a file between multiple
projects. The VSS Branch command allows parallel development on different versions of the same file,
and the Merge command allows you to merge the changes made to two different versions of a file into a
single file.
The Show History command is one of the many features you can use to keep track of a file's version
history.
5. Click OK.
6. STUpload will allow the user to work on only one document within a single instance of the
application. Change the application type setting from Multiple Documents to Single Document.
Click Next to proceed to Step 2, the database support screen.
7. STUpload will provide the facility to query a database, but it will use ActiveX Data Objects to
achieve this. Therefore, you do not need to implement MFC database support. Leave None
selected and click Next to proceed to Step 3, the compound document options screen.
8. You will not be implementing compound document support for STUpload, so leave None selected
and click Next to proceed to Step 4, the application features screen.
9. Accept the default options in this dialog box, and then click Advanced to open the Advanced
Options dialog box.
10. In the File Extension text box of the Document Template Strings page, type stu as the file
11. In the Filter Name box, the File New Name box and the File Type Name box, change the word
STUplo to read STUpload.
12. Click Close to close the Advanced Options dialog box, and click Next to proceed to Step 5 of the
AppWizard.
13. Leave the default options set and click Next to proceed to Step 6 of the AppWizard.
14. You are going to implement a scrollable view for the STUpload application to allow you to view
windows that are larger than the screen area. To enable this feature, you will derive your view
class from the MFC CScrollView class, which implements scroll bars and scrolling behavior.
Make sure that the CSTUploadView class is selected in the upper pane, and click CScrollView in
the Base Class drop-down list.
15. Click Finish, check through the New Project Information screen, and click OK to create the
project.
16. When the project is created, expand the STUpload Classes icon in the ClassView window to
view the classes that AppWizard has created for you. Press F7 to build the project.
17. Press CTRL+F5 to run the STUpload application. On the File menu, click Open. Note how the
standard file dialog box is expecting you to open STUpload files with the .stu extension that you
specified in Step 4 of the AppWizard. Select Cancel to close the Open File dialog box.
18. Using the mouse, drag the bottom-right corner of the STUpload application window, and shrink
the window until it is only a couple of inches square. Note how scrollbars appear automatically
along the edges of the window client area.
19. On the File menu, click Exit to close the STUpload application.
Review
1. What project configurations are created for you automatically by the MFC AppWizard?
2. Where, in the AppWizard, can you configure features of the application windows?
3. What kinds of help are available from the Visual C++ IDE?
4. What can you set on the C/C++ tab of the Project Settings dialog box?
5. Why might you need to use the Get Latest Version command of Visual SourceSafe?
6. Under what circumstances might you use the Visual SourceSafe Merge facility?
Answers