5.4 The Visual C++ IDE

Visual C++ is an integrated programming environment (IDE) within which the developer can edit, rebuild, and debug an object-oriented program written in C++. As with othr IDEs, the developer does not need to leave the environment in order to perform any of these construction tasks, and all of the construction tasks are performed using the same user intrface. Only the simplest usage and the most basic commands of Visual C++ are described here; more sophisticated uses and the full range of commands and options are detailed in the on-line help site and in numerous books specifically about Visual C++.

The User Interface

The user interface of Visual C++ consists of four primary areas:

  • the control area: this area contains a collection of buttons and pull-down menus. With these controls, the developer is able to select options that define the appearance and operation of the environment and to execute commands.

  • the editing area: this area displays for viewing and editing the source files that compose the system being developed. Each file is represented in its own subwindow, which can be independently moved, resized, minimized (or docked at the edge of the editing area), maximized (to take up the entire editing area), or closed.

  • the viewing area: this area presents different views of the elements that form the system being developed. Two common views are the file view and the class view. The contents of files selected from these views are shown in the editing area.

  • the output area: this is a scrollable subwindow that contains messages from the current command being executed in the environment. The format of this area may change depending on the command. Two common uses for the output area area to show error messages generated by the compiler and to communicate information between the debugger and the developer.

These areas may be hidden, resized, or repositioned according to the user's preferences and the operation being performed. For example, during a lng editing session the viewing and output areas may be hidden or minimized to allow more room to display the files being edited.

The Project Workspace

The central organizing concept of Visual C++ is the project workspace, which automates the mechanical aspects of rebuilding and debugging systems. The project workspace automatically detects and records the dependencies among source-code files, and its environment facilitates debugging by providing a high-level (symbolic) set of debugging operations. Each project workspace has a name assigned by the developer upon its creation. As with other names, the project workspace name should be indicative of the program (system) meaning; in the simplest case, each program (system) that the developer constructs is represented by a separate project workspace. The contents of a project workspace is stored in a subdirectory on disk. The subdirectory and the project workspace have the same name. The location in the file system where the subdirectory is stored is chosen by the user when the workspace is created.

To create a new project workspace, simply follow the steps shown in the table below. This sequence of steps creates an empty project workspace.

Creating a Project Workspace
  1. Choose "New" from the File pull-down menu.
  2. Choose "Project Workspace" from the list presented in the dialog box; then click OK.
  3. In the New Project Workspace dialog box there are three items to specify:
    1. the Type of the project workspace; for simple command line programs choose "Console Application" and for the other programs used in this book choose "Application"
    2. the Name of the project workspace, and
    3. the Location of the subdirectory where the files of the project workspace will be stored. A browse button allows the developer to navigate in the file system to find an appropriate location for this subdirectory.

The File pull-down menu also contains other commonly used commands for manipulating the project workspace. The most frequently used commands are:

  • Save, Save All: saves the current contents of one or all files in the project workspace to the subdirectory
  • Close Workspace: close the current project workspace (typically used before exiting from Visual C++)
  • Open Workspace : opens a previously created, saved, and closed project workspace

These commands are sufficient for use with simple project workspaces.

A workspace is stored in a file that has the suffix .mdp. When using the Open Workspace command, use the file-browser dialogue to locate the file whose name is that of the desired project workspace and whose suffix is .mdp.

Adding Classes to a Project Workspace

Classes can be added to a project workspace by creating the source-code files and inserting them into the project workspace. The source code for classes that exist prior to the creation of the project workspace (e.g., classes being reused from prior projects) can be directly inserted into the project workspace, while new classes must first be created and then inserted into the project workspace.

The view area presents the user with a class view and a file view of the contents of the project workspace. The class view shows the names of all of the classes in the project workspace. When the user clicks on a class name, the file containing the definition of the class is opened and presented in the editing area. The file view shows the names of all of the implementation files in the project workspace. When the user clicks on a file name, that file is opened and presented in the editing area. When following the common practice of putting each class definition in a separate header file and the entire implementation of that class in a separate file, the class view is a means of accessing the header files and the file view a means of accessing the implementation files.

The steps for creating new source-code files are listed in the table below. When a new text file is first created, it is given a default name by the project workspace. A good practice is to immediately use the Save As command in the File menu to give the file a unique, proper name. The files that are shown in the editing area can be edited using the simple built-in editor commands that are listed in the Edit menu. Keyboard shortcuts are also available for these editing commands. Periodically the Save command should be used to save the currrent contents of the file to disk. If the user has modified several open files, the Save All command is a convenient way to ensure that all of these changes are committed to disk.

Creating Source Code Files
  1. Choose New from the File pull-down menu.
  2. Choose Text File from the list presented in the dialog box; then click OK.
  3. Use the Save As command from the File pull-down menu to give the file a meaningful name.
  4. Create the new source code in the new text window that appears in the editing area. The source code can be created in this file using the built-in editor features.
  5. Periodically use the Save command from the File pull-down menu to save the contents of the file.

Inserting a source-code file in the project workspace charges the project workspace with the responsibility of determining the dependencies associated with the inserted files and recompiling the file (if it is an implementation file) as needed. The user does not need to take any overt action to analyze the dependencies; simply inserting the files into the project workspace is sufficient. Files can be inserted into the project workspace using the steps below.

Inserting Files into the Project Workspace
  1. Under the Insert menu, select the command "Files into Project".
  2. From the file selection dialog box that is presented, choose the files to be inserted into the project; several files can be inserted at once.
  3. Click the Add button on the dialog box.

It is important to remember that source-code files created within the Visual C++ IDE are not automatically inserted in the project workspace; each such file must be explicitly inserted using the above procedure.

Rebuilding the System

The Build pull-down menu contains three frequently used commands for building and runnng the executable program created from the files in the project workspace. These commands are shownin Table 5-6. The Compile command compiles the single file that has the focus (contains the cursor) in the editing area. This command is useful in the early stages of developing a class or when the code for the class has been heavily modified. Compiling such a class by itself allows the developer to correct any syntax mistakes or other problems for that class before attempting to rebuild the entire system. The Build command is used to rebuild an executable system using the current contents of the source files in the project workspace. When the system has been rebuilt sucessfully, the Execute command can be used to run the new system.

Frequently Used Commands to Rebuild the System
  • Compile: compile the current file (the one that has the focus in the editing area).
  • Build: create an executable file using the files in the project workspace, recompiling only those files deemed necessary by the dependencies understood by the project workspace.
  • Execute: run the executable file.

The project workspace assists the developer in locating lines of code where syntax errors have been detected by the compiler. Compilation errors generated by either the Compile or the Build commands are shown in the output area. When the user clicks on one of these the corresponding file is displayed in the viewing area and the cursor is positioned at the line where the error occurred. The complete error message is shown in the status line immediately below the output area.

Two other commands, summarized in Table 5-7, in the Build menu, Build All and Update All Dependencies, are useful when the developer wants to be certain that a consistent version of the system has been built. The Build All command forces a comlete recompilation of the system, ignoring all exisiting object files. All implementation files are recompiled using the current contents of the source-code files in the project workspace. The Update All Dependencies command prompts the project workspace to insure that its list of dependencies is up to date. These two commands help the developer to eliminate the problems caused by an inconsistent version of the system accidentally being built.

Other Useful Commands in the Build Menu
  • Build All: recompile all files, disregarding any dependency and change information.
  • Update All Dependencies: rescan all files and reconstruct the dependency information to ensure that the project workspace has valid dependency information.


Specifying Paths, Symbols, and Libraries

Visual C++ provides a mechanism for specifying search paths and defining options that affect the rebuilding of the system. Search paths are defined using the Tools menu and other options are specified using the Build menu.

Paths in the file system to be searched for include files or libraries are specified by using the Options command in the Tools menu. When the Options command is selected, a tabbed dialogue box appears; select the Directories tab. The Directories entry has a selection box labelled "Show directories for," two of whose selections are "Include files" and "library files", which correspond to paths in the file system to search for include files and libraries, respectively. The main part of the Directories entry displays the current set of paths for the current selection. Current paths may be deleted or new paths may be added to the set. When the sets of paths have been set correctly, press the OK button.

The Settings selection in the Build menu is used to set other options, including symbols and libraries. The Setting selection produces a tabbed dialogue box. The two tabs of interest here are labelled C/C++ and Link. Clicking on the C/C++ tab reveals an area that contains a writeable text area labelled "Preprocessor definitions:". Any preprocessor symbol that is to be treated as defined can be added to the comma-separated list of symbols. Selecting the Link tab reveals an area that contains a writeable text area labelled "Object/library modules:" to which can be added any libraries that should be used in linking the executable file.

©1998 Prentice-Hall, Inc.
A Simon & Schuster Company
Upper Saddle River, New Jersey 07458

Legal Statement