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
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.
The File pull-down menu also contains other commonly used commands for manipulating the project workspace. The most frequently used commands are:
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.
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.
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.
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.
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.