When you buy Microsoft Visual C++, you actually get Microsoft Developer Studio with the Visual C++ component activated. Developer Studio is far more than just a compiler, and you have far more to learn than you may think. The interface is very visual, which means that there are many possibilities greeting you when you first run Visual C++.
Microsoft Visual C++ is one component of the Microsoft Developer Studio. The capabilities of this one piece of software are astonishing. It is called an integrated development environment because within a single tool, you can:
Visual C++ is, technically speaking, just one component of Developer Studio. You can buy, for example, Microsoft's FORTRAN compiler, and use it in Developer Studio as well. Looking at it another way, Visual C++ is more than just Developer Studio, since the Microsoft Foundation Classes (MFC) that are becoming the standard for C++ Windows programming are a class library and not related to the development environment. In fact, the major C++ compilers all use MFC now. However, for most people, Visual C++ and Developer Studio mean the same thing, and in this book the names are used interchangeably.
With Visual C++, you work on a single application as a project. A project is a collection of files: source, headers, resources, settings, and configuration information. Developer Studio is designed to enable work on all aspects of a single project at once. You create a new application by creating a new project. When you want to work on your application, you open the project (a file with the extension .mdp) rather than open each code file independently. The interface of Developer Studio, shown in Figures 1.1 and 1.2, is designed to work with a project and is divided into several zones. The zones that make up the Developer Studio interface are:
TIP |
Open Developer Studio and try to resize the panes and follow along as functions are described in this chapter. |
The Project Workspace window determines which way you look at your project, and what is in the main working area: documentation, code files, or resources (menus, icons, and dialog boxes). Each of these views is discussed in detail in a separate section in this chapter:
Developer Studio actually uses two different files to keep track of all the information about your project. The make file, with a .mak extension, contains the names of all the files in the project, what directories they are in, compiler and linker options, and other information required by everyone who may work on the project. The project workspace file, with a .mdp extension, contains the name and location of the make file and all your personal settings for Developer Studio-colors, fonts, toolbars, which files are open and how their MDI windows are sized and located, breakpoints from your most recent debugging session, and so on. If someone else is going to work on your project, you give that person a copy of the make file but not the project workspace file. To open the project, open the project workspace file. The make file is opened automatically.
When you first start Developer Studio and no project is open, the only tab in the Project Workspace window is the InfoView tab. When a project is open there are other tabs to choose from. Clicking the InfoView tab brings a table of contents into the Project Workspace window and an InfoViewer topic window into the main working area, as shown in Figures 1.1 and 1.2. The table of contents is an outline that can be expanded or collapsed. Double-clicking an entry in the table of contents displays that entry in the InfoViewer topic window.
TIP |
If your Project Workspace window is too narrow for reading the topic headings in the table of contents, you can scroll the window with the horizontal scroll bar. You can also pause the mouse cursor over any topic heading, and a small box like a Tool Tip appears showing the full heading for the topic. |
Within the InfoViewer topic window, documentation is displayed as hypertext. Words and phrases that are highlighted act as links; clicking a link displays different information. There are two kinds of links: popups and jumps. Clicking a popup link, displayed in gray by default, pops up a small window, which typically contains a definition. Clicking a jump link, displayed in underlined green by default, closes the topic you are viewing and opens a related topic. To change the colors of the links, choose Tools, Options to bring up the Options dialog box. As shown in Figure 1.3, select the Format tab and choose InfoViewer Topic window from the list box on the left. Be cautious when changing these colors; they were chosen for a reason.
By default, the InfoViewer window is maximized to fill the entire working area, and the title bar of Developer Studio has InfoViewer Topic added to it. By clicking the Restore button under the main Restore button for all of Developer Studio, you can arrange the InfoViewer MDI window within the main working area. This allows you to compare two help topics or a help topic and a piece of code. Figure 1.4 shows the InfoViewer window restored; notice how the toolbar stays with the window. There is an InfoViewer toolbar as well'it is the lowest toolbar in these figures, and is discussed in Chapter 2 "Developer Studio Commands." If you want, the topic window can also be minimized.
Figure 1.4 : The InfoViewer topic window does not have to be maximized.
The toolbar across the top of the InfoViewer topic window has the following seven buttons:
If you are short on screen space you can get rid of this toolbar and use the keyboard shortcuts instead. Right-click in the topic window and uncheck Show Toolbar. If you forget the keyboard shortcuts, all these commands are available from the right-click menu, shown in Figure 1.5.
Clicking the Resource View tab in the project workspace window brings up an expandable and collapsible outline of the visual elements of your program: accelerators, dialog boxes, icons, menus, the string table, toolbars, and version information. These resources define the way users interact with your program. Chapter 17, "Building Menus and Dialogs," covers the work involved in creating and editing these resources. The next few sections cover the way in which you can look at completed resources.
TIP |
Open one of the projects on the CD that comes with this book, or a sample project from Visual C++, and follow along as functions are described in this section. |
Accelerators associate key combinations with menu items. Figure 1.6 shows an accelerator resource created by AppWizard. All these accelerator combinations are made for you when you create a new application. You can add hot keys for specific menu items if necessary.
Figure 1.6 : Accelerators associate key combinations with menu items.
Dialog boxes are the way your application gets information from users. When a dialog resource is being displayed in the main working area, as in Figure 1.7, a control palette floats over the working area. Each small icon on the palette represents a control (edit box, list box, button, and so on) that can be inserted onto your dialog box. By choosing Edit, Properties, the Properties box shown in Figure 1.7 is displayed. Here the behavior of a control or of the whole dialog box can be controlled.
Figure 1.7 : Dialog boxes get information from the user.
TIP |
Click the pushpin at the top left of the Properties box to keep it displayed even when a different item is highlighted. The box displays the properties of each item you click. |
This method of editing dialog boxes is one of the reasons for the name Visual C++. In this product, if you want a button to be a little lower on a dialog box, you click it with the mouse, drag it to the new position, and release the mouse button. Similarly, if you want the dialog box larger or smaller, grab a corner or edge and drag it to the new size just like any other sizable window. Before Visual C++ was released, the process would have involved coding and pixel counting, and taken many minutes rather than just a few seconds. This visual approach to dialog box building made Windows programming accessible to many more programmers.
Icons are small bitmaps that represent your program or its documents. For example, when a program is minimized an icon is used to represent it. A larger version of that icon is used to represent both the program and its documents within an Explorer window. And when an MDI window is minimized within your application, the minimized window is represented by an icon. Figure 1.8 shows the default icon provided by AppWizard for minimized MDI windows. One of your first tasks is to replace this with an icon that more clearly represents the work your program performs.
Figure 1.8 : Icons represent your application and its documents.
An icon is a 32´32 pixel bitmap that can be edited with any number of drawing tools, including the simple bitmap editor included in Developer Studio. The interface is very similar to Microsoft Paint or Microsoft Paintbrush in Zoom mode. You can draw one pixel at a time by clicking, or freehand lines by clicking and dragging. You can work on the small or zoomed versions of the icon and see the effects at once in both places.
Menus are the way that users tell your program what to do. Keyboard shortcuts (accelerators) are linked to menu items, as are toolbar buttons. AppWizard creates the standard menus for a new application, and you edit those and create new ones in this view. Later, you'll use ClassWizard to connect menu items to functions within your code. Figure 1.9 shows a menu displayed in the resource view. Choose Edit, Properties to display the properties box for the menu item. Every menu item has the following three components:
Figure 1.9 : Menus are the way your application receives commands.
The string table is a list of strings within your application. Many strings, such as the static text on dialog boxes or the prompts for menu items, can be accessed in far simpler ways than through the string table, but some are reached only through it. For example, a default name or value can be kept in the string table, and changed without recompiling any code, though the resources will have to be compiled and the project linked. Each of these could be hard coded into the program, but then changes would require a full recompile. Figure 1.10 shows the string table for a sample application. To change a string, bring up the Properties dialog box and change the caption. Strings cannot be changed within the main working area.
Figure 1.10 : The string table stores all the prompts and text in your application.
Toolbars are the lines of small buttons typically located directly underneath the menus of an application. Each button is linked to a menu item, and its appearance depends on the state of the menu item. If a menu item is grayed, the corresponding toolbar button is grayed as well. If a menu item is checked, the corresponding toolbar button is typically drawn as a pushed-in button. In this way, toolbar buttons serve as indicators as well as mechanisms for giving commands to the application.
A toolbar button has two parts: a bitmap of the button and a resource ID. When a user clicks the button, it is just as though the menu item with the same resource ID was chosen. Figure 1.11 shows a typical toolbar and the properties of the File, Open button on that toolbar. In this view you can change the resource ID of any button, and edit the bitmap with the same tools used to edit icons.
Figure 1.11 : Toolbar buttons are associated with menu items through a resource ID.
One of the goodies that comes with Visual C++ is an installation program called Install Shield. This utility is discussed in more detail in Chapter 32, "Additional Advanced Topics." It uses the version information resource when installing your application on a user's machine. For example, if a user is installing an application that has already been installed, the installation program may not have to copy as many files. It may alert the user if an old version is being installed over a new version, and so on.
When you create an application with AppWizard, version information like that in Figure 1.12 is generated for you automatically. Before attempting to change any of it, make sure you understand how installation programs use it.
Figure 1.12 : Version information is used by install programs.
The Class view shows the classes in your application. Under each class, the member variables and functions are shown, as demonstrated in Figure 1.13. Member functions are shown first with a purple icon next to them, followed by member variables with a turquoise icon. Protected members have a key next to the icon, while private members have a padlock.
Figure 1.13 : The Class view shows the functions and variables in each class in your application.
Double-clicking a function name brings up the source for that function in the main working area, as shown in Figure 1.13. Double-clicking a variable name brings up the header file in which the variable is declared, as shown in Figure 1.14.
Figure 1.14 : The Class view makes it easy to view source or header code.
Right-clicking the name of a member function brings up a substantial shortcut menu, with the following menu items:
Right-clicking the name of a member variable brings up a shortcut menu with less menu items. The items are as follows:
When the main working area is displaying a source or header file, you can edit your code as described in the later section "Editing Your Code."
The File view is much like the Class view in that you can display
and edit source and header files. However, it gives you access
to parts of your file that are outside of class definitions, and
makes it easy to open noncode files like resources and plain text.
The project workspace window contains a tree view of the source
files in your project. All the header files are grouped together
under Dependencies, as shown in Figure 1.16.
Figure 1.16 : The File view displays source and header files.
Double-clicking a filename displays that file in the main working area. You can then edit the file (even if it is not a source or header file) as described in the later section "Editing Your Code."
Across the bottom of the Developer Studio screen is the Output view. This is a tabbed view that shows output and error messages from a variety of Developer Studio functions.
TIP |
If there is no Output view on your screen, choose View, Output from the menu to restore the view. |
The four tabs in the Output View are the following:
For most people, editing code is the most important thing you do in a development environment. If you've used any other editor or word processor before, you can handle the basics of the Developer Studio editor right away. You should be able to type in code, fix your mistakes, and move around in source or header files just by using the basic Windows techniques you would expect to be able to use. But since this is a programmer's editor, there are some nice features you should know about.
To add text into a file, click where you want the text to go and start typing. By default, the editor is in Insert mode, which means your new text pushes the old text over. To switch to Overstrike mode, press the Ins key. Now your text types over the text that is already there. The OVR indicator on the status bar reminds you that you are in Overstrike mode. Pressing Ins again puts you back in Insert mode. Move around in the file by clicking with the mouse or use the cursor keys. To move a page or more at a time, use the PageUp and PageDown keys or the scrollbar at the right hand side of the main working area.
By default, the window for the file you are editing is maximized within the main working area. You can click the Restore button at the top right, just under the Restore button for all of Developer Studio, to show the file in a smaller window. If you have several files open at once you can arrange them so that you can see them side-by-side, as shown in Figure 1.17.
Figure 1.17 : Your files are in MDI windows so you can edit several at once, side-by-side.
Much of the time, you will want to perform an action on a block of text within the editor. First, you select the block by clicking at one end of it and, holding the mouse button down, moving the mouse to the other end of the block, then releasing the mouse button. This should be familiar from so many other Windows applications. Not surprisingly, at this point you can copy or cut the block to the Clipboard, replace it with text you type, or with the current contents of the Clipboard, or delete it.
TIP |
To select columns of text, as shown in Figure 1.18, hold down the Alt key as you select the block. |
One thing you may have noticed is the color scheme used to present your code. Developer Studio highlights the elements of your code with syntax coloring. By default, your code is black, with comments in green and keywords (reserved words in C++ like public, private, new, or int) in blue. You can also arrange for special colors for strings, numbers, or operators (like + and -) if you want, using the Format tab of the Options dialog box, reached by choosing Tools, Options. This is discussed in more detail in Chapter 2 "Developer Studio Commands."
Syntax coloring can really help you spot silly mistakes. If you forget to close a C-style comment, the huge swath of green in your file points out the problem right away. If you type inr where you meant to type int, the inr isn't blue, and that alerts you to a mistyped keyword. This means you can prevent most compiler errors before you even compile.
Many of the actions you are likely to perform are available on the shortcut menu. The items on that menu are as follows:
Not all the items are enabled at once-for example, Cut and Copy are only enabled when there is a selection. Insert File Into Project is only enabled when the file you are editing is not in the project you have open. All of these actions have menu and toolbar equivalents and are discussed more fully in Chapter 2 "Developer Studio Commands."
The editing window for source (.cpp) files has a toolbar that the windows for header (.h) and other files do not. (You can see it in Figures 1.13, 1.17, and 1.18.) This toolbar is commonly called the WizardBar and is a shortcut to the actions you would most likely perform with ClassWizard. (Using ClassWizard is covered in detail in Chapter 3 "AppWizard and ClassWizard.") The following four elements are on the bar:
If you are a newcomer to Visual C++ and ClassWizard, the WizardBar is probably a little terse for you right now. After you are more familiar with using ClassWizard to connect Windows messages to your code, you will appreciate the convenience this feature offers.
The user interface of Developer Studio is very visual, encouraging you to move from view to view of your project: looking at your resources, classes, and files, or checking the online documentation. The main screen is divided into panes which you can resize to suit your own needs, and there are many shortcut menus, reached by right-clicking in different places on the screen, to simplify common tasks. This chapter has covered about half of the interface of Visual C++. To learn more, check these chapters and parts: