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++.
Developer Studio is more than just a compiler.
This tabbed window makes it simple and fast to access any part of your application.
Find your way around Books Online.
Access your menus, dialog boxes, bitmaps, and other user interface resources.
See all your classes, and their variables and functions. See at a glance whether a variable is public or private, or double-click a function to jump to its source code.
Organize your files and open them easily.
At the bottom of the screen, these areas inform you and provide results.
This is where the real work gets done: you type in code, fix mistakes, and watch your application take shape.
You can reach Developer Studio commands through menu selections.
Once youíve learned the basics, toolbars are a faster way to work.
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 (IDE) because within a single tool, you can perform the following:
Visual C++ is, technically speaking, just one component of Developer Studio. You can buy, for example, Microsoft's Visual J++ compiler and use it in Developer Studio as well. Looking at it another way, Visual C++ is more than just Developer Studio, because 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.
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. There are many shortcut menus, reached by right-clicking different places on the screen, to simplify common tasks.
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 .dsw) rather than opening each code file independently. The interface of Developer Studio, shown in Figures B.1 and B.2, is designed to work with a project and is divided into several zones.
Fig. B.1 The Developer Studio interface presents a lot of information. The Project Workspace window is on the left.
Fig. B.2 When the Project Workspace window is narrowed, the words on the tabs are replaced with icons.
The zones that make up the Developer Studio interface are as follows:
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, including the following:
Developer Studio uses two different files to keep track of all the information about your project. The project workspace file, with a .dsw 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. There is also a project file, with a .dsp extension, for each project within the workspace. The workspace options file, with a .opt extension, contains 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 project workspace file and project file but not the project options file.
To open the project, open the project workspace file. The other files are opened automatically.
Earlier versions of Visual C++ used .mdp files to store project information. When you open an old file, you are asked if it should be converted to the new format. The conversion process creates .dsw, .dsp, and .opt files for you and does not delete your old files.
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 B.1 and B.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.
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 ToolTip 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. The documentation is written in HTML and is displayed just as it would be in Microsoft Internet Explorer, the web browser from Microsoft. While most of the links lead to other help topics on your hard drive or CD, some of them lead out onto the Internet for the very latest information.
Your settings in Microsoft Internet Explorer affect how InfoViewer in Developer Studio displays documentation. For example, if you turn off image display in Explorer, images will not be displayed in InfoViewer until you click them.
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 B.3 shows the InfoViewer window restored. The topic window can also be minimized.
Fig. B.3 The InfoViewer topic window does not have to be maximized.
Many InfoViewer commands are on the Help menu or the InfoViewer toolbar, both discussed in the second half of this chapter. There is a shortcut menu, reached by right-clicking anywhere within the InfoViewer topic window. As shown in Figure B.4, it features commands that are commonly used when looking at a page of HTML in Microsoft Internet Explorer, and is not very useful while using Visual C++.
Fig. B.4 The InfoViewer topic window has a number of shortcuts available on the right-click menu.
Clicking the ResourceView 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 2, "Dialog Boxes and Controls;" Chapter 9, ìBuilding a Complete Application: ShowString;î and Chapter 10, ìStatus Bars and Toolbarsî cover the work involved in creating and editing these resources. The next few sections cover the way in which you can look at completed resources.
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. Showstring, the sample application from Chapter 9, ìBuilding a Complete Application: ShowString,î is a good choice since it uses most of the features described in this section.
Accelerators associate key combinations with menu items. Figure B.5 shows an accelerator resource created by AppWizard. All of these accelerator combinations are made for you when you create a new application. You can add hot keys for specific menu items, if necessary.
Fig. B.5 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 B.6, a control palette floats over the working area. (If itís not displayed, right-click the menu bar and check Controls to display it.) 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 View, Properties, the Properties box shown in Figure B.6 is displayed. Here the behavior of a control or of the whole dialog box can be controlled.
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.
Fig. B.6 Dialog boxes get information from the user.
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 B.7 shows the default icon provided by AppWizard for minimized MDI windows. One of your first tasks after building any application is to replace this with an icon that more clearly represents the work your program performs.
An icon is a 32X32 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.
Fig. B.7 Icons represent your application and its documents.
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 B.8 shows a menu displayed in the resource view. Choose View, Properties to display the properties box for the menu item. Every menu item has the following three components:
Fig. B.8 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 B.9 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.
Fig. B.9 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 B.10 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.
Fig. B.10 Toolbar buttons are associated with menu items through a resource ID.
Good installation programs use 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 B.11 is generated for you automatically. Before attempting to change any of it, make sure you understand how installation programs use it.
Fig. B.11 Version information is used by install programs.
The ClassView shows the classes in your application. Under each class, the member variables and functions are shown, as demonstrated in Figure B.12. 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.
Fig. B.12 The ClassView 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 B.12. Double-clicking a variable name brings up the header file in which the variable is declared.
Right-clicking a class name brings up a shortcut menu, shown in Figure B.13, with these items:
Fig. B.13 Common commands related to classes are on the ClassView shorcut menu for a class.
Fig. B.14 Never again forget to add part of a function declaration or definition when you use the Add Member Function shortcut.
Fig. B.15 Simplify adding member variables with this shortcut.
Menu items that appear on a toolbar have their toolbar icon next to them on the menu. Make note of the icon; the next time you want to choose that item, perhaps you can use a toolbar instead.
Right-clicking the name of a member function brings up a substantial shortcut menu, with the following menu items:
Fig. B.16 The Call Graph window lists all the functions that your function calls, and all the functions they call, and so on.
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 FileView is much like the ClassView 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 non-code files like resources and plain text.
The project workspace window contains a tree view of the source files in your project. The default categories used are Source Files, Header Files, Resource Files, and Help Files (if you project has Help). You can add your own categories by right-clicking anywhere in the FileView and choosing New Folder, then specifying which file extensions belong in the new category.
Fig. B.17 The FileView displays source and header files.
Double-clicking a file name 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.
If there is no Output view on your screen, choose View, Output from the menu to restore the view.
The five tabs in the Output View are the following:
If you have installed the Enterprise Edition of Visual C++, there is a sixth tab, SQL Debugging. For more information, see Chapter 23, ìSQL and the Enterprise Edition.î
For most people, editing code is the most important task 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 because 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 Insert 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 Insert 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 Page Up and Page Down keys or the scroll bar 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 B.18.
Fig. B.18 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, replace it with with the current contents of the Clipboard, or delete it.
To select columns of text, as shown in Figure B.19, hold down the Alt key as you select the block.
Fig. B.19 Selecting columns makes fixing indents much simpler. Hold down the Alt key as you select the block.
You may have noticed 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.
Syntax coloring can 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.
If you build Web pages and still use Notepad from time to time so that you can see the tags, youíre in for a pleasant surprise. Open an HTML file in Developer Studio and see HTML syntax coloring in action. Youíll never go back to Notepad.
Many of the actions you are likely to perform are available on the shortcut menu that appears when you right-click within a file you are editing. 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 later in this chapter.
Developer Studio has many menus. Some commands are three or four levels deep under the menu structure. In most cases, there are far quicker ways to accomplish the same task, but for a new user, the menus are an easier way to learn because you can rely on reading the menu items as opposed to memorizing shortcuts. There are nine menus on the Developer Studio menu bar, as follows:
The following section presents each Developer Studio menu in turn, and mentions keyboard shortcuts and toolbar buttons where they exist.
The File menu, shown in Figure B.20, collects most of the commands that affect entire files or the entire project.
Fig. B.20 The File menu has actions for files like Open, Close, and Print.
Choosing this menu item brings up the New dialog box, shown in Figure B.21. This tabbed dialog box is used to create new files, projects, workspaces, or other documents. The Project tab is used to start AppWizard, discussed for the first time in Chapter 1, ìBuilding Your First Application.î
Fig. B.21 The New dialog box is used to create new files or workspaces.
This dialog box is an easy way to create a blank file, give it a name, and insert it into your project all in one step.
Choosing this item brings up the Open dialog box, as shown in Figure B.22. (It's the standard Windows File Open dialog box, so it should be pretty familiar.) The file type defaults to Common Files with .c, .cpp, .cxx, .h, or .rc extensions. By clicking the drop-down box, you can open almost any kind of file, including executables and workspaces.
Fig. B.22 The familiar File Open dialog box is used to open a variety of file types.
Don't forget the list of recently opened files further down the File menu. That can save a lot of typing or clicking.
Choosing the File, Close item closes the file that has focus; if no file has focus, the item is grayed. You can also close a file by clicking the cancel button, depicted by an X, in the top-right corner. You may also close the window by double-clicking the icon in the upper-right corner. (The icon used to be the system menu, shown with a minus on a button.)
Use this item to open a workspace. (You can use File, Open and change the file type to Project Workspace, but using File, Open Workspace is quicker.)
Use this item to close a workspace. The current workspace is closed automatically when you create a new project or open another workspace, so you wonít use this menu item very often.
Use this item to save the file that has focus at the moment; if no file has focus, the item is grayed. There is a Save button on the Standard toolbar as well.
Use this item to save a file and change its name at the same time. It saves the file that has focus at the moment; if no file has focus, the item is grayed.
This item saves all the files that are currently open. All files are saved just before a compile and when the application is closed, but if you aren't compiling very often and are making a lot of changes, it's a good idea to save all your files every 15 minutes or so. (You can do it less often if the idea of losing that amount of work doesn't bother you.)
Use this item to change the name of a file without leaving a copy under the old name.
This item brings up the Page Setup dialog box, shown in Figure B.23. Here you specify the header, footer, and marginsóleft, right, top, and bottom. The header and footer can contain any text including one or more special fields, which you add by clicking the arrow next to the edit box or entering the codes yourself. The codes are:
Fig. B.23 The Page Setup dialog box lays out your printed pages the way you want.
Choosing this item prints the file with focus according to your Page Setup settings. (The item is grayed if no file has focus.) The Print dialog box, shown in Figure B.24, has you confirm the printer you want to print on. If you have some text highlighted, the Selection radio button is enabled. Choosing it lets you print just the selected text; otherwise, only the All radio button is enabled, which prints the entire file. If you forget to set the headers, footers, and margins before choosing File, Print, the Setup button brings up the Page Setup dialog box discussed in the previous section. There is no way to print only certain pages or to cancel printing once it has started.
Fig. B.24 The Print dialog box confirms your choice to print a file.
The recent files and workspaces items, between Print and Exit, each lead to a cascading menu. The items on the secondary menus are the names of files and workspaces which have been opened most recently, up to the last four of each. These are real time-savers if you work on several projects at once. Whenever you want to open a file, before you click that toolbar button and prepare to point and click your way to the file, think first if it might be on the File menu. Menus aren't always the slower way to go.
Probably the most familiar Windows menu item of all, this closes Developer Studio. You can also click the X in the top-right corner, or double-click what used to be the system menu in the top left. If you have made changes without saving, you get a chance to save each file on your way out.
The Edit menu, shown in Figure B.25, collects actions related to changing text in a source file.
Fig. B.25 The Edit menu holds items that change the text in a file.
The Undo item reverses whatever you just did. Most operations, like text edits and deleting text, can be undone. When Undo is disabled, it is an indication that nothing needs to be undone or you cannot undo the last operation.
There is an Undo button on the Standard toolbar. Clicking the button displays a stack (reverse order list from most recent to least recent) of operations that can be undone. You must select a contiguous range of undo items including the first, second, and so on. You cannot pick and choose.
As you undo actions, the name given to the operations move from the Undo to the Redo list (Redo is next to Undo on the toolbar). If you undo a little too much, choose Edit, Redo to un-undo them (if that makes sense).
This item cuts the currently highlighted text to the Clipboard. That means a copy of it goes to the Clipboard, and the text itself is deleted from your file. The Cut button (represented as scissors) is on the Standard toolbar.
Editing buttons on the toolbar are grouped next to the scissors (Cut). Edit, Copy copies the currently selected text or item to the Windows Clipboard.
Choosing this item copies the Clipboard contents at the cursor, or replaces the highlighted text with the Clipboard contents if any text is highlighted. The Paste item and button are disabled if there is nothing in the Clipboard in a format appropriate for pasting to the focus window. In addition to text, you can copy and paste menu items, dialog box items, and other resources. The Paste button is on the Standard toolbar.
Edit, Delete clears the selected text or item. If what you deleted is undeletable, then the Undo button is enabled and the last operation is added to the Undo button combo box. Deleted material does not go to the Clipboard and cannot be retrieved except by undoing the delete.
This item selects everything in the file with focus that can be selected. For example, if a text file has focus, the entire file is selected. If a dialog box has focus, every control on it is selected.
To select many items on a dialog box, you can click the first item and then Ctrl+click each of the remaining items. It is often faster to use Edit, Select All to select everything, and then Ctrl+click to unselect the few items you do not want highlighted.
The Find dialog box shown in Figure B.26 enables you to search for text within the file that currently has the focus. Enter a word or phrase into the Find What edit box. The following check boxes set the options for the search:
Fig. B.26 The Find dialog box is used to find a string within the file that has focus.
If you highlight a block of text before selecting Edit, Find, that text is put into the Find What box for you. If no text is highlighted, the word or identifier under the cursor is put into the Find What box.
A typical use for the Find dialog box is to enter some text and click the Find Next button until you find the precise occurrence of the text for which you are searching. But you may want to combine the Find feature with bookmarks (discussed a little later in this section), and put a bookmark on each line that has an occurrence of the string. Click the Mark All button in the Find dialog box to add temporary, unnamed bookmarks on match lines; they are indicated with a blue oval in the margin.
There is a Find edit box on the Standard toolbar. Enter the text you want to search for in the box and press Enter to search forward. Regular expressions are used if you have turned them on using the Find dialog box. To repeat a search, click the Find Next or Find Previousbuttons on the Standard toolbar (these are icons with binoculars with clockwise and counter-clockwise arrows, respectively).
Regular Expressions
Many of the find and replace operations within Developer Studio can be made more powerful with regular expressions. For example, if you want to search for a string only at the end of a line, or one of several similar strings, you can do so by constructing an appropriate regular expression, entering it in the Search dialog box, and instructing Developer Studio to use regular expressions for the search. A regular expression is some text, combined with special characters that represent things that can't be typed, like "the end of a line" or "any number" or "three capital letters."
When regular expressions are being used, some characters give up their usual meaning and instead stand in for one or more other characters. Regular expressions in Developer Studio are built from ordinary characters mixed in with these special entries, shown in Table B.1.
You don't have to type these in if you have trouble remembering them. Next to the Find What box is an arrowhead pointing to the right. Click there to bring up a shortcut menu of all these fields, and click any one of them to insert it into the Find What box. (You need to be able to read these symbols to understand what expression you are building, and there's no arrowhead on the toolbarís Find box.) Remember to select the Regular Expressions box so that these regular expressions are evaluated properly.
Here are some examples of regular expressions:
- ^test$ matches only test alone on a line.
- doc[1234] matches doc1, doc2, doc3, or doc4 but not doc5.
- doc[1-4] matches the same strings as above but requires less typing.
- doc[^56] matches doca, doc1, and anything else that starts with doc and is not doc5 or doc6.
- If the Find What box contains (\Good\) morning and the replace box is \1 afternoon, then Good morning is changed to Good afternoon.
- H\~ello matches Hillo and Hxllo (and lots more) but not Hello.
- \{x\!y\}z matches xz and yz.
- New *York matches New York but also NewYork and New York.
- New +York matches New York and New York but not NewYork.
- New.*k matches Newk, Newark, and New York, plus lots more.
- \:n matches 0.123, 234, and 23.45 (among others) but not -1C.
- World$ matches World at the end of a line but World\$ matches only World$ anywhere on a line.
Table B.1óRegular Expression Entries
Entry | Matches |
[af] | Start of the line. |
$ | End of the line. |
. | Any single character. |
[] | Any one of the characters within the brackets (use - for a range, [af] for "except"). |
\~ | Anything except the character that follows next. |
* | Zero or more of the next character. |
+ | One or more of the next character. |
\( \) | Doesn't match specially, but saves part of the match string to be used in the replacement string. Up to nine portions can be tagged like this. |
\{\!\} | Either of the characters within the {}. |
{\\} | Just like []. |
\:a | A single letter or number. |
\:b | White space (tabs or spaces). |
\:c | A single letter. |
\:d | A single numerical digit. |
\:n | An unsigned number. |
\:z | An unsigned integer. |
\:h | A hexadecimal number. |
\:i | A string of characters that meets the rules for C++ identifiers (starts with a letter, number, or underscore). |
\:w | A string of letters only. |
\:q | A quoted string surrounded by double or single quotes. |
\ | Removes the special meaning from the character that follows. |
This useful command searches for a word or phrase within a large number of files at once. In its simplest form, shown in Figure B.27, you enter a word or phrase into the Find What edit box, restrict the search to certain types of files in the In Files of Type box, and choose the folder to conduct the search within in the In Folder edit box. The following check boxes in the bottom half of the dialog box set the options for the search:
Fig. B.27 The simplest Find in Files approach searches for a string within a folder and its subfolders.
Using Advanced Text Finding Features
At the bottom right of the Find in Files dialog box is the Advanced button. Clicking it expands the dialog box shown in Figure B.28 and allows you to search several different folders at once.
Fig. B.28 Advanced Find in Files searches for a string within several folders and their subfolders.
If you highlight a block of text before selecting Find in Files, that text is put into the Find What box for you. If no text is highlighted, the word or identifier under the cursor is put into the Find What box.
The results of the Find in Files command appear in the Find in Files 1 tab (unless you ask for pane 2) of the output window; the output window will be visible after this operation if it was not already. You can resize this window like any other window, by holding the mouse over the border until it becomes a sizing cursor, and you can scroll around within the window in the usual way. Double-clicking a file name in the output list opens that file with the cursor on the line where the match was found.
This item brings up the Replace dialog box, shown in Figure B.29. It is very similar to the Find dialog box but is used to replace the found text with new text. Enter one string into the Find What edit box and the replacement string into the Replace With edit box. The three check boxesóRegular Expression, Match Case, and Match Whole Word Onlyóhave the same meaning as on the Find dialog box (discussed in the previous section). The Replace In radio buttons allow you to restrict the search-and-replace operation to a block of highlighted text, if you prefer.
Fig. B.29 The Replace dialog box is used to replace one string with another.
To see the next match before you agree to replace it, click Find Next. To replace the next match or the match you have just found, click Replace. If you are confident that there won't be any false matches, you can click Replace All to do the rest of the file all at once. (If you realize after you click Replace All that you were wrong, there is always Edit, Undo.)
The Go To dialog box (see Figure B.30) is a central navigation point. It enables you to go to a particular line number (the default), address, reference, or bookmark, among other things. To use the Go To dialog box, select something from the Go To What list on the left; if Line is selected enter a line number, if Bookmark is selected pick the particular bookmark from the combo box, and so on.
Fig. B.30 The Go To dialog box moves you around within your project.
The Go To What box contains the following choices:
The pushpin in the upper-left corner of this dialog box is used to ìpinî it to the screen so that it stays in place after you have gone to the requested location. Click the pin to unpin the dialog box from the screen so that it goes away after the jump.
This item is used to manage the bookmarks within your text files, which are completely independent of any InfoViewer bookmarks you may have set. The bookmark list is shown in Figure B.31. Note that temporary bookmarks set by the Find command are not included in this list.
Fig. B.31 The Bookmarks dialog box manages the bookmarks you have set in text files.
To add a named bookmark for the line you are on and have it saved with the file, type a name in the Name box and click Add. To go to a named bookmark, choose it from the list box and click Go To. There are buttons on the Edit toolbar to add or delete a bookmark at the cursor, move to the next or previous bookmark, and clear all bookmarks in the file.
If you have Visual InterDev installed and are working with an ActiveX control, this menu item will let you edit its settings. Building ActiveX controls is discussed in Chapter 17, ìBuilding an ActiveX Control.î
This item is used to edit an HTML layout with Visual InterDev.
Choosing this item brings up a cascading menu with the following items:
A breakpoint pauses program execution. The Edit, Breakpoints item displays the Breakpoints dialog box, shown in Figure B.32 and discussed in Reference C, "Debugging."
Fig. B.32 The Breakpoints dialog box is used in debugging your application.
The View menu, shown in Figure B.33, collects actions that are related to the appearance of Developer Studioówhich windows are open, what toolbars are visible, and so on.
Fig. B.33 The View menu controls the appearance of Developer Studio.
This InterDev-related command is used to edit Web page scripts.
ClassWizard is probably the most-used tool in Developer Studio. Whenever you add a resource (menu, dialog box, control, and so on), you connect it to your code with ClassWizard. When you are working with ActiveX, you use ClassWizard to set up properties, methods, and events. If you use custom messages, you use ClassWizard to arrange for them to be caught. You learn how to use ClassWizard starting in Chapter 2, ìDialogs and Controls.î
All changed files are saved when you bring up ClassWizard, just as they are saved before a compile. If you have been making changes that you may not want saved, don't bring up ClassWizard.
This item brings up the Resource Symbols dialog box, shown in Figure B.34. It displays the resource IDs, such as ID_EDIT_COPY, used in your application. The large list box at the top of the dialog box lists resource IDs, and the smaller box below it reminds you where this resource is usedóon a menu, in an accelerator, in the string table, and so on. The buttons along the right side are used to make changes. Click New to create a new resource ID, Delete to delete this resource ID (if it is not in use), Change to change the ID (if it is in use by only one resource), and View Use to open the resource (menu, string table, and so on) that is highlighted in the lower list.
Fig. B.34 The Resource Symbols dialog box displays resource IDs.
Choosing this item brings up the Resource Includes dialog box, as shown in Figure B.35. It is unusual for you to need to change this generated material. In the rare cases where the resource.h file generated for you is not quite what you need, you can add extra lines with this dialog box.
Fig. B.35 The Resource Includes dialog box lets you insert extra instructions into the file that describes the resources of your project.
This item hides all the toolbars, menus, Output window, and Project Workspace window, giving you your entire screen as the main working area. One small toolbar appears whose only button is Toggle Full Screen. Click that button to restore the menus, toolbars, and windows.
Choosing this item brings up the Workspace window, if it is hidden. It does not take away the Project Workspace window. To hide it, right-click the window and choose Hide, or press Shift+Esc while the window has focus. There is a Workspace button on the Standard toolbar which hides or displays the window.
This item re-opens your most recently viewed InfoViewer topic.
Choosing this item brings up a tabbed window of lists relevant to InfoViewer, like that shown in Figure B.36. The tabs are Search, Lookup, See Also, and History.
Fig. B.36 The InfoViewer Results tabbed dialog box collects InfoViewer lists in one spot.
This item brings up the Output window, if it is hidden. To hide the Output window, right-click it and choose Hide, or press Shift+Esc while the window has focus. The Output window opens automatically when you build your project or use Find in Files.
This cascading menu deals with windows used while debugging, which are discussed in Reference C, "Debugging." It contains the following items:
Choosing this item brings up a property sheet. The property sheets for different items vary widely, as shown in Figures B.37, B.38, and B.39, which illustrate the property sheet for an entire source file, an accelerator table selected in the Project Workspace window, and one key in that accelerator table, respectively.
Fig. B.37 The property sheet for a source file reminds you of the name and size, and lets you set the language (used for syntax coloring) and tab size.
Fig. B.38 The property sheet for an accelerator table is where you set the language, enabling you to include multiple tables in one application.
Fig. B.39 The property sheet for an entry in an accelerator table gives you full control over the keystrokes associated with the resource ID.
Property sheets are a powerful way of editing non-source file entities, such as resources. For functions and variables, however, it's usually easier to make the changes in the source file. Some rather obscure effects can only be achieved through property sheets. For example, to turn off syntax coloring for a file, use the property sheet to set the language to None. (The effect will be observed after the window is repainted by Windows.)
The property normally disappears as soon as you click something else. If you click the pushpin button in the top-left corner, it stays "pinned" to the screen as you work, displaying the properties of all the entities you are working with.
The Insert menu, shown in Figure B.40, collects actions related to inserting something into your project or one of its files.
Fig. B.40 The Insert menu is one way to add items to a project or a file.
Use this item to create a header and source file for a new class and add it to this project. The New Class dialog box is shown in Figure B.41. Note the drop-down box that makes specifying the base class simpler.
Fig. B.41 The New Class dialog box simplifies creating a new class.
Use this item to add a new resource to your project. The Insert Resource dialog box, shown in Figure B.42, appears. Choose the type of resource to be added and click OK.
Fig. B.42 The Insert Resource dialog box is one way to add resources to your project.
There are buttons on the Resource toolbar to add a new dialog box, menu, cursor, icon, bitmap, toolbar, accelerator, string table, or version.
Use this item to copy an existing resource, changing only the language (for example, from US English to Canadian French) or the condition (for example, building a debug version of a dialog box). Your project will have different language versions of the resource, allowing you to use compiler directives to determine which resource is compiled into the executable.
When you are creating an ActiveX control with the Active Template Library (ATL), use this item to insert ATL objects into your project. See Chapter 21, ìThe Active Template Library.î
The Project menu, shown in Figure B.43, holds items associated with project maintenance. The items in this menu are:
Fig. B.43 The Project menu simplifies project maintenance.
If you have several projects in your workspace, this item sets which project is active.
This item brings up a cascading menu with the following choices:
Fig. B.44 The Insert Files into Project dialog box looks very much like a File Open dialog box.
This item allows you to make one project dependent on another so that when one project is changed, its dependents are rebuilt.
This item brings up the Project Settings dialog box, which has the following eight tabs:
Fig. B.45 The General tab of the Project Settings dialog box governs where files are kept.
Fig. B.46 The C/C++ tab of the Project Settings dialog box governs compiler settings in eight categories, starting with General.
Fig. B.47 The Link tab of the Project Settings dialog box governs linker settings in five categories, starting with General.
Fig. B.48 The Resources tab of the Project Settings dialog box governs resources settings, including language.
Fig. B.49 The Browse Info tab of the Project Settings dialog box turns on or off the powerful browse feature.
To see the last few tabs, click the right-pointing arrow at the end of the list of tabs. You can adjust the settings for each configuration (Debug, Release, and so on) separately or all at once. Many of the panes have a Reset button that restores the settings to those you chose when you first created the project.
The Build menu, shown in Figure B.50, holds all the actions associated with compiling, running, and debugging your application.
Fig. B.50 The Build menu is used to compile, link, and debug your application.
The Build menu will be a hub of activity when your are ready to compile and debug. The Build menu item names are:
Choosing this item compiles the file with focus. This is a very useful thing to do when you are expecting to find errors or warnings, such as the first time you compile after a lot of changes. For example, if there is an error in a header file that is included in many source files, a typical build produces error messages related to that header file over and over again as each source file is compiled. If there are warnings in one of your source files, a typical build links the project, but you might prefer to stop and correct the warnings. There is a Compile button on the Project toolbar, represented by a stack of papers with an arrow pointing downward.
This item compiles all the changed files in the project and then links them. There is a Build button on the Project toolbar.
This item compiles all files in the project, even those that have not been changed since the last build, and then links them. There are times when a typical build misses a file that should be recompiled, and using this item corrects the problem.
Typically a project contains at least two configurations: Debug and Release. Usually you work with the Debug configuration, changing, building, testing, and changing the project again until it is ready to be released, and then build a Release version. If you ever need to build several configurations at once, use this menu item to bring up the Batch Build dialog box shown in Figure B.51. Choose Build to compile only changed files, and Rebuild All to compile all files. If the compiles are successful, links follow.
Fig. B.51 The Batch Build dialog box builds several configurations of your project at once.
This item deletes all the intermediate and output files so that your project directory contains only source files.
The list of dependencies tracks which files use (depend on) other files within your project. If a header file changes, all the source files that include that header file must be compiled during a build. When header files include other header files, or when files are added to a project, the list of dependencies can get messed up. This item regenerates the list and gets everything running smoothly again.
Debugging is a lengthy topic, discussed in Reference C, "Debugging."
Build Debugger Remote Connection
It is possible to run a program on one computer and debug it on another. As part of that process, you use this menu item to connect the two computers. This is discussed in Reference C, "Debugging."
Choosing the Build, Execute item runs your application without bringing up the debugger.
Build Set Active Configuration
The Set Active Project Configuration dialog box, shown in Figure B.52, sets which of your configurations is active (typically Debug and Release). The active configuration is built by the Build commands.
Fig. B.52 The Set Active Project Configuration dialog box sets the default configuration.
Choosing this item brings up the Configurations dialog box, shown in Figure B.53. Here you can add or remove configurations. Use Project Settings to change the settings for the new configuration.
Fig. B.53 The Configurations dialog box lets you add to the standard Debug and Release configurations.
The profiler is a powerful tool to identify bottlenecks in your applications. It is discussed in Chapter 24, ìImproving Your Applicationís Performance.î
The Tools menu, shown in Figure B.54, simplifies access to add-in tools, and holds some odds-and-ends leftover commands that don't fit on any other menu.
Fig. B.54 The Tools menu organizes add-in tools.
Tools Source Browser (Alt+F12)
The browser is a very powerful addition to Developer Studio; you use it whenever you go to a definition or reference, check a call graph, or otherwise explore the relationships among the classes, functions, and variables in your project. However, it's unusual to access the browser through this menu item, which brings up the Browse dialog box shown in Figure B.55. You are more likely to use Edit, Go To, a Go To item from the right-click menu, or one of the 11 buttons on the Browse toolbar.
Fig. B.55 The Browse dialog box is a less-common way to browse your objects, functions, and variables.
Tools Close Source Browser File
Whenever you rebuild your project, your browse file is rebuilt, too. If you rebuild your project outside Developer Studio with a tool like NMAKE, you should close the browse file first via the menu choice so that it can be updated by that tool.
A number of tools are added to the Tools menu when you install Visual C++, and you can add more tools with the Customize menu item, discussed next.
Choosing this option brings up the Customize dialog box. The Commands pane of that dialog box is shown in Figure B.56 with the File buttons showing. The nine buttons correspond to items on the File menu, and if you would like one of those items on any toolbar, simply drag it from the dialog box to the appropriate place on the toolbar and release it. The list box on the left side of the Toolbar tab lets you choose other menus, each with a collection of toolbar buttons you can drag to any toolbar. Remember that the menu bar is now a toolbar to which you can drag buttons, if you want.
Fig. B.56 The Commands pane of the Customize dialog box lets you build your own toolbars.
If your toolbars are all messed up, with extra buttons or missing buttons or both, the Reset All Menus button on this dialog returns objects to their normal state.
The Toolbars pane, shown in Figure B.57, is one way to control which toolbars are displayed. As you can see, you can also suppress ToolTips if they annoy you, or turn on larger toolbar buttons if you have the space for them. (The Standard toolbar in Figure B.57 has large buttons.)
Fig. B.57 The Toolbars tab of the Customize dialog box is one way to turn a toolbar on or off, and the only way to govern ToolTips and button size.
The Tools tab lets you add programs to the Tools menu, and the Keyboard tab lets you change the keyboard shortcuts for commands, or add shortcuts for commands without them. The new Add-Ins and Macro Files tab lets you add macros, which are written in VBScript and can automate many Developer Studio tasks, or add-ins, which can be written in any language and also automate Developer Studio tasks, to your workspace.
This item gathers up a great number of settings and options that relate to Developer Studio itself. For example, Figure B.58 shows the Editor tab of the Options dialog box. If there is a feature of Developer Studio you don't like, you can almost certainly change it within this large dialog box.
Fig. B.58 The Editor tab of the Options dialog box is where you change editor settings.
The tabs are as follows:
Fig. B.59 The Workspace tab of the Options dialog box sets which views dock and which float as well as reload options.
If you work on the same project all the time, check the Reload Last Project at Startup box on the Workspace tab of the Option dialog box. Loading the Developer Studio and the last project then becomes a one-step process; simply loading the Developer Studio will load the last project, too. If you work on a variety of different projects, uncheck this box so that Developer Studio comes up more quickly.
This item brings up the Macro dialog box, shown in Figure B.60. Here you can record or play back simple macros, or edit a set of recorded keystrokes by adding VBScript statements.
Fig. B.60 The Macro dialog box is the nerve center for creating, editing, and using macros.
The Window menu, shown in Figure B.61, controls the windows in the main working area of Developer Studio.
Fig. B.61 The Window menu controls the windows in the main working area.
Choosing this item opens another window containing the same source file as the window with focus. The first window's title bar is changed, with :1 added after the file name; in the new window, :2 is added after the file name. Changes made in one window are immediately reflected in the other. The windows can be scrolled, sized, and closed independently.
Choosing this window puts cross hairs over the file with focus; when you click the mouse, the window is split into four panes along the lines of these cross hairs. You can drag these boundaries about in the usual way if they are not in the right place. Scrolling one pane scrolls its companion pane as well, so that the views stay in sync. To unsplit a window, drag a boundary right to the edge of the window, and it disappears. Drag away both the horizontal and vertical boundaries, and the window is no longer split.
This menu item governs whether the window with focus is a docking view or not. It is disabled when the main working area has focus.
Choosing this item closes the window with focus and its associated file. If you have any unsaved changes, you are asked whether to save them or not.
Choosing this item closes all the windows in the main working area. If you have any unsaved changes, you are asked whether to save them or not.
This item switches focus to the next window. The order of the windows can be determined by looking at the list of open windows at the bottom of the menu.
This item switches focus to the previous window.
This item arranges all the windows in the main working area in the familiar cascade pattern, like the one shown in Figure B.62. Minimized windows are not restored and cascaded.
Fig. B.62 Arranging windows in a cascade makes it easy to switch between them.
This item arranges all the windows in the main working area so that each is the full width of the working area, as shown in Figure B.63. The file that had focus when you chose this item is at the top.
Fig. B.63 When windows are tiled horizontally, each is the full width of the main working area.
This item arranges all the windows in the main working area so that each is the full height of the working area, as shown in Figure B.64. The file that had focus when you chose this item is at the left.
Fig. B.64 When windows are tiled vertically, each is the full height of the main working area.
The bottom section of this menu lists the windows in the main working area so that you can move among them even when they are maximized. If there are more than nine open windows, only the first nine are listed. The rest can be reached by choosing Window, Windows.
This item brings up the Windows dialog box, shown in Figure B.65. From here you can close, save, or activate any window.
Fig. B.65 The Windows dialog box allows access to any window in the main working area.
There are two Help systems for Developer Studio. One is InfoViewer; the other the standard Windows Help system. Pressing F1 in most dialog boxes brings up the standard Help, but choosing items on this menu, shown in Figure B.66, activates InfoViewer.
Fig. B.66 The Help menu is your doorway to the InfoViewer system.
This item opens the Workspace window if it is hidden, switches to the InfoViewer tab, and displays the table of contents.
This item brings up the Search dialog box, which can be used as an index or for queries. With the Index tab, shown in Figure B.67, you type all or part of an index term, and, as you type, the list of index terms scrolls. To open the InfoViewer topic, select a term, click List Books, then select a book from the lower list box and click Display.
Fig. B.67 The Index tab of the Search dialog box uses the index to find InfoViewer topics.
With the Query tab, shown in Figure B.68, you enter one or more keywords, then submit the query. Results are gathered into a query results list like that shown in Figure B.69. Double-click any topic to display it.
Fig. B.68 The Query tab of the Search dialog box is the way to submit queries that search through the entire InfoViewer text.
Fig. B.69 The Query Results list shows the topics that match your query.
This menu item brings up the Developer Studio home page, which has links to a number of other useful InfoViewer topics or Web pages.
You can set bookmarks on any InfoViewer topic to help you find it again when you need it. While most people use the toolbar buttons to set, delete, and go to InfoViwer bookmarks, you can also use this menu item, which brings up the dialog box shown in Figure B.70.
Fig. B.70 The InfoViewer Bookmarks dialog box lets you add, edit, or delete bookmarks as well as jump to them.
When you move from one InfoViewer topic to another by following a link, the table of contents in the Workspace pane is not adjusted. Sometimes you can lose track of where you have jumped to. Choosing this item will redisplay the table of contents with the current topic highlighted.
Searches through the entire InfoViewer text can be slow, and can produce too many false hits. You can restrict your use of InfoViewer to selected books within InfoViewer, called a subset. Choosing this item brings up the Define Subset dialog box, shown in Figure B.71.
Fig. B.71 The Define Subset dialog box is used to narrow the topics used within InfoViewer.
Once one or more subsets of InfoViewer have been defined, choose this item to set one of them to the default, used in query and index searches and the table of contents display.
This item does not involve InfoViewer. Choosing it brings up the Help Keyboard dialog box, shown in Figure B.72. Use the drop-down box at the top to choose the commands for which you want to see keystrokes: Bound commands (those with keystrokes assigned), All commands, or commands from the File, Edit, View, Insert, Build, Debug, Tools, Window, or Help menus. Commands related to Images and Layout are also available.
Fig. B.72 The Help Keyboard dialog box displays the keystrokes associated with commands.
Click the title bars across the top of the table to sort the display by that column. Keystrokes cannot be changed here; choose Tools, Customize and use the Keyboard tab to change keystrokes.
Choosing this item brings up the Tip of the Day, like that in Figure B.73. Some are Windows tips; others are specific to Developer Studio. If you can't wait to see a new tip each time you open Developer Studio, click Next Tip to scroll through the list. If you are annoyed by these tips on startup, deselect the Show Tips at Startup box.
Fig. B.73 The Tip of the Day is a great way to learn more about Developer Studio.
If you think you need technical support, start here. Not only do you learn how to get that support, but you may find the answer to your question.
One of the ways Microsoft supplies information about Developer Studio and other products is through the World Wide Web. Choosing this item brings up a cascading menu with a list of Web sites. Choosing any these displays the pages within InfoViewer by default. You can arrange to launch another browser if you prefer: choose Tools, Options, click the InfoViewer tab, and unselect Use Infoviewer for Microsoft on the Web. Now your default browser will be used.
Choosing this item brings up the About box for Developer Studio, which includes, among other information, your Product ID.
After you are familiar with the sorts of actions you are likely to request of Developer Studio, the toolbars save you a lot of time. Instead of choosing File, Open, which takes two clicks and a mouse move, it is simpler to just click the Open button on the toolbar. There are, however, 11 toolbars plus a menu bar in this product, and that means a lot of little icons to learn. In this section, you will see each toolbar and which menu items the buttons correspond to.
Figure B.74 shows all the toolbars that are available in Developer Studio. The quickest way to turn several toolbars on and off is with the Toolbars dialog box, which you can also use to turn ToolTips on or off, and set whether the tips include the shortcut keys for the command. Any of these toolbars can dock against any of the four edges of the working area, as shown in Figure B.75. To move a docked toolbar, drag it by the wrinklesóthe two vertical bars at the far right. You move an undocked toolbar like any other window. When it nears the edge of the main working area, the shape change shows you it will dock. Take some time to experiment moving toolbars around until you find a configuration that suits you.
Fig. B.74 Developer Studio has 12 toolbars, shown here floating.
Fig. B.75 Developer Studio toolbars can dock against any edge.
Two of the most important toolbars are the Standard and the Build Mini-bar. These are discussed in the sections that follow. For a full description of what each button does, refer to the section earlier in this chapter for the corresponding menu item.
The Standard Toolbar helps you maintain and edit text and files in your workspace. Table B.2 names each Standard tool button and its equivalent menu operation.
Table B.2óStandard Toolbar Buttons and Equivalent Menu Operations
Button Name | Menu Equivalent |
New Text File | File, New |
Open | File, Open |
Save | File, Save |
Save All | File, Save All |
Cut | Edit, Cut |
Copy | Edit, Copy |
Paste | Edit, Paste |
Undo | Edit, Undo |
Redo | Edit, Redo |
Workspace | View, Workspace |
Output | View, Output |
Window List | Window, Windows |
Find in Files | Edit, Find in Files |
Find | Edit, Find |
Back | N/A |
Forward | N/A |
Stop | N/A |
Refresh | View, Refresh |
Home | Help, Documentation Home Page |
Search | Help, Search |
ClassWizard | View, ClassWizard |
The names for the Build Mini-bar buttons, which are related to compiling and debugging, are defined in Table B.3.
Table B.3óBuild Mini-bar Buttons and Equivalent Menu Commands
Button Name | Menu Equivalent |
Compile | Build, Compile |
Build | Build, Build |
Stop Build | Build, Stop Build |
Execute | Build, Execute |
Go | Build, Start Debug, Go |
Insert/Remove Breakpoint | N/A |
You can display any or all of the toolbars, add and remove buttons to them, and generally make Developer Studio into a product that works the way you work. Experiment and see what simplifies your software development effort.
© 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.