This appendix covers some basic information about the Developer Studio Integrated Development Environment.
Developer Studio includes a sophisticated editor as one of its tools. The editor is integrated with the other parts of Developer Studio; files are edited in a Developer Studio child window. You use the Developer Studio editor to edit C++ source files that will be compiled into Windows programs. The editor supplied with Developer Studio is similar to a word processor, but instead of fancy text-formatting features, it has features that help make writing source code easy.
You can use almost any editor to write C++ source code, but there are several reasons to consider using the editor integrated with Developer Studio. The editor includes many features that are found in specialized programming editors.
The easiest way to learn about the Developer Studio editor is to edit a file and run through a few common actions, such as creating a new source file, saving and loading files, and using a few keyboard commands.
To edit a new source file, click the New Text File icon on the toolbar. The New Text File icon looks like a blank piece of paper with a yellow highlight in one corner. You can also open a new source file using the menu by following these steps:
Each of the preceding methods creates an empty source file ready for editing. Type the source code from Listing A.1 into the new file.
// This is a comment int main() { return 0;
} The source code in Listing A.1 is a legal C++ program, although it doesn't actually do anything. As you typed the source code into the editor, the colors for some of the words should have changed. This is called syntax highlighting, and it's one of the features of Developer Studio's editor.
The first line in Listing A.1 begins with //, which is used to mark the beginning of a single-line comment in a C++ program. By default, comments are colored green by the Developer Studio editor. In contrast, int and return are colored blue to indicate that they are C++ keywords.
Another editor feature is called smart indenting. This feature automatically arranges your text as you type, applying formatting rules to your text as each word or line is entered into the editor. For example, enter the source code from Listing A.2 into the text editor. Press Return at the end of each line, but do not add spaces or tabs. As each line is typed, the editor rearranges the text into a standard format for you.
class CFoo { int nFoo; int nBar; public: CFoo();
} The source code provided in this book follows the same formatting convention used by the Developer Studio editor. Although some coding styles might be more compact, this style is very easy to read.
To save the contents of the editor, click the Save icon on the toolbar. The Save icon looks like a small floppy disk. You can also press Ctrl+S or select Save from the File menu.
When updating an existing source file, you don't see a dialog box, and no further action is needed on your part. The existing file is updated using the current contents of the editor. If you save a new file, you see the Save As dialog box, and you must choose a location and filename for the new source file. Save the contents of Listing A.2 in the C:\ directory using the name CFoo.cpp. After saving the file, close CFoo.cpp by selecting Close from the File menu.
To save a file under a new name, select Save As from the File menu or press F12. Enter the new path and filename using the Save As dialog box as described previously.
To open an existing source file, click the Open icon on the toolbar. The Open icon looks like a folder that is partially open. You can also press Ctrl+O or select Open from the File menu. Any of these methods brings up the File Open dialog box.
To open the CFoo.cpp file for editing, pop up the File Open dialog box and navigate to the C:\ directory. Select the CFoo.cpp file and click the button labeled Open. The CFoo.cpp file is loaded into the editor.
As discussed in the first hour, a large set of editing commands is available from the keyboard. Although most editor commands are also available from the menu or toolbar, the following commands are frequently used from the keyboard:
This is only a small list of the available keyboard commands. To see a complete list, select Keyboard from the Help menu.
InfoViewer is the online help system integrated into Developer Studio. Usually, the indexes used by the InfoViewer are copied to your hard disk, and the actual database remains on the CD. This spares a great deal of hard disk space. If you would like to speed up InfoViewer, run Visual C++ setup again and install InfoViewer to the hard disk. Select a custom installation procedure and make sure you check the InfoViewer box.
Because Visual C++ is not sold with a documentation set, InfoViewer is the only documentation that is included with the product. Although the online documentation is also available from Microsoft in book form, it costs you extra.
InfoViewer has several advantages over hard-copy documentation:
You interact with the InfoViewer help system in two windows:
To get context-sensitive help from InfoViewer, press F1. You select a topic based on the current window and cursor position, and you see the InfoViewer window containing context-sensitive help. If you press F1 while editing a source file, help is provided for the word under the cursor. If there is more than one possible help topic, you see a list of choices.
Open a new document for editing, as described earlier in this chapter, and enter the source code provided in Listing A.3.
int main() { return 0;
} Every word in this example has a help topic. To get context-sensitive help, move the cursor to any word in Listing A.3 and press the F1 key. The help topic is displayed in a dockable window next to your source code. To return the windows to their original sizes and hide the InfoViewer window, press Escape.
To search the InfoViewer keyword list, open the Search dialog box by selecting Search from the Help menu or by right-clicking in the InfoViewer window. The Search dialog box enables you to select a help topic by entering a keyword. The keyword list box scrolls as you make your entry, which is helpful when you're not quite sure how to spell a keyword.
The Search dialog box also enables you to create a query in order to find a topic. You can use a query to search the entire contents, a subset of the contents, or the results of the last query. The last option is useful when you're narrowing the scope of a search. You can apply the query to the entire contents of InfoViewer or to only the titles of each topic.
A query can be as simple as a single word, or it can be used to look for words that are adjacent or close to each other. You can use the AND, OR, NEAR, and NOT operators to create queries. Operators aren't required to be capitalized, although it helps to set off the operator from your search items. For example, to find all the topics where the words dialog and tab are close to each other, use the following query:
dialog NEAR tab
To look for topics where the word main is found but exclude any topics that contain the word WinMain, use the following query:
main NOT WinMain
A third way to use InfoViewer is to browse through the contents pane in the project workspace window. The contents pane displays the titles for every available topic, arranged in an easy-to-use tree view.
When the InfoViewer contents tree is completely collapsed, the contents pane displays the titles for the top level of the available topics. The titles displayed at the top level are somewhat like the titles of a series of books; the icon even looks like a book. When the book icon is closed, a plus sign appears next to the book title, indicating that the book can be opened to display its contents. Click the plus sign to open the book icon and expand the contents tree to display the contents of the open book. Topics are represented by icons that look like a page of text. To display the selected topic, click the topic icon; the InfoViewer topic window opens. Clicking the plus sign also changes the plus sign to a minus, which you can click to close the book.
© Copyright, Macmillan Computer Publishing. All rights reserved.