📄 chxb.htm
字号:
<P>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."</P>
<H3><A ID="I14" NAME="I14"><B>Looking at Your Code, Arranged by File</B></A></H3>
<P>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. </P>
<P>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 Ne<U>w</U> Folder, then specifying which file extensions belong in the new category.</P>
<A HREF="FFfig17.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig17.gif"><b>Fig. B.17</b></A>
<P><I>The FileView displays source and header files.</I></P>
<P>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."</P>
<H3><A ID="I15" NAME="I15"><B>Output and Error Messages</B></A></H3>
<P>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.</P>
<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">
<P>If there is no Output view on your screen, choose <U>V</U>iew, <U>O</U>utput from the menu to restore the view.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<P>The five tabs in the Output View are the following:</P>
<ul>
<li> <I>Build</I>. Displays the results of compiling and linking.</P>
<li> <I>Debug</I>. Used when debugging, as discussed in <A HREF="indexc.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/indexc.htm" target="text">Reference Appendix C</A>, "Debugging."</P>
<li> <I>Find in Files 1</I>. Displays the results of the Find in Files search, discussed later in this chapter.</P>
<li> <I>Find in Files 2</I>. An alternate display window for Find in Files results, so that you can preserve earlier results.</P>
<li> <I>Results</I>. Displays results of tools like the profiler, discussed in <A HREF="index24.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index24.htm" target="text">Chapter 24</A>, "Improving Your Application’s Performance."</P>
</ul>
<P>If you have installed the Enterprise Edition of Visual C++, there is a sixth tab, SQL Debugging. For more information, see <A HREF="index23.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index23.htm" target="text">Chapter 23</A>, “SQL and the Enterprise Edition.”</P>
<H3><A ID="I16" NAME="I16"><B>Editing Your Code</B></A></H3>
<P>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.</P>
<P><A ID="I17" NAME="I17"><B>Basic Typing and Editing</B></A></P>
<P>To add text into a file, click where you want the text to go and start typing. By default, the editor is in <I>Insert mode</I>, which means your new text pushes the old text over. To switch to <I>Overstrike mode</I>, press the Insert key. Now your text
types over the text that is already there. The <font color="#008000">OVR</font> 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.</P>
<P>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.</P>
<A HREF="FFfig18.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig18.gif"><b>Fig. B.18</b></A>
<P><I>Your files are in MDI windows so you can edit several at once, side-by-side.</I></P>
<P><A ID="I18" NAME="I18"><B>Working with Blocks of Text</B></A></P>
<P>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.</P>
<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">
<P>To select columns of text, as shown in Figure B.19, hold down the Alt key as you select the block.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<A HREF="FFfig19.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig19.gif"><b>Fig. B.19</b></A>
<P><I>Selecting columns makes fixing indents much simpler. Hold down the Alt key as you select the block.</I></P>
<P><A ID="I19" NAME="I19"><B>Syntax Coloring</B></A></P>
<P>You may have noticed the color scheme used to present your code. Developer Studio highlights the elements of your code with <I>syntax </I><I>coloring</I>. By default, your code is black, with comments in green and keywords (reserved words in C++ like
<font color="#008000">public</font>, <font color="#008000">private</font>, <font color="#008000">new</font>, or <font color="#008000">int</font>) in blue. You can also arrange for special colors for strings, numbers, or operators (like <font
color="#008000">+</font> and <font color="#008000">-</font>) if you want, using the Format tab of the Options dialog box, reached by choosing <U>T</U>ools, <U>O</U>ptions. </P>
<P>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 <B>inr</B> where you meant to type <B>int</B>, the <font
color="#008000">inr</font> isn't blue, and that alerts you to a mistyped keyword. This means you can prevent most compiler errors before you even compile.</P>
<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">
<P>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.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<P><A ID="I20" NAME="I20"><B>Shortcut Menu</B></A></P>
<P>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:</P>
<ul>
<li> <I>Cu</I><I><U>t</U></I>. Cuts the selected text to the Clipboard.</P>
<li> <I><U>C</U></I><I>opy</I>. Copies the selected text to the Clipboard.</P>
<li> <I><U>P</U></I><I>aste</I>. Replaces the selected text with the Clipboard contents, or if no text is selected, inserts the Clipboard contents at the cursor.</P>
<li> <I>Insert File Into Project</I>. Adds the file you are editing to the project you have open.</P>
<li> <I>Open</I>. Opens the file whose name is under the cursor. Especially useful for header files, because you don’t need to know what folder they are in.</P>
<li> <I>Go To </I><I><U>D</U></I><I>efinition</I>. Opens the file where the item under the cursor is defined (header for a variable, source for a function) and positions the cursor at the definition of the item.</P>
<li> <I>Go To R</I><I><U>e</U></I><I>ference</I>. Positions the cursor at the next reference to the variable or function whose name is under the cursor.</P>
<li> <I>Insert/Remove Breakpoint</I>. Inserts a breakpoint at the cursor, or removes one that is already there.</P>
<li> <I>Enable Breakpoint</I>. Enables a disabled breakpoint (breakpoints are discussed in <A HREF="indexc.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/indexc.htm" target="text">Reference C</A>, "Debugging").</P>
<li> <I>Class</I><I><U>W</U></I><I>izard</I>. Brings up ClassWizard.</P>
<li> <I><U>P</U></I><I>roperties</I>. Brings up the property sheet.</P>
</ul>
<P>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.</P>
<H3><A ID="I21" NAME="I21"><B>Learning the Menu System</B></A></H3>
<P>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:</P>
<ul>
<li> <I>File</I>. For actions related to entire files, like opening, closing, and printing.</P>
<li> <I>Edit</I>. For copying, cutting, pasting, searching, and moving about.</P>
<li> <I>View</I>. For changing the appearance of Developer Studio, including toolbars and subwindows like the Workspace window.</P>
<li> <I>Insert</I>. For adding files or components to your project.</P>
<li> <I>Project</I>. For dealing with your entire project.</P>
<li> <I>Build</I>. For compiling, linking, and debugging.</P>
<li> <I>Tools</I>. For customizing the Developer Studio and accessing stand-alone utilities.</P>
<li> <I>Window</I>. To change which window is maximized or has focus.</P>
<li> <I>Help</I>. To use the InfoViewer system (not the usual online help).</P>
</ul>
<P>The following section presents each Developer Studio menu in turn, and mentions keyboard shortcuts and toolbar buttons where they exist.</P>
<P><A ID="I22" NAME="I22"><B>Using File Menu</B></A></P>
<P>The File menu, shown in Figure B.20, collects most of the commands that affect entire files or the entire project.</P>
<A HREF="FFfig20.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig20.gif"><b>Fig. B.20</b></A>
<P><I>The File menu has actions for files like Open, Close, and Print.</I></P>
<P><A ID="I23" NAME="I23"><B>File New (Ctrl+N)</B></A></P>
<P>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 <A
HREF="index01.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index01.htm" target="text">Chapter 1</A>, “Building Your First Application.”</P>
<A HREF="FFfig21.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig21.gif"><b>Fig. B.21</b></A>
<P><I>The New dialog box is used to create new files or workspaces.</I></P>
<P>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.</P>
<P><A ID="I24" NAME="I24"><B>File Open (Ctrl+O)</B></A></P>
<P>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.</P>
<A HREF="FFfig22.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/chxb/FFfig22.gif"><b>Fig. B.22</b></A>
<P><I>The familiar File Open dialog box is used to open a variety of file types.</I></P>
<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">
<P>Don't forget the list of recently opened files further down the <U>F</U>ile menu. That can save a lot of typing or clicking.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<P><A ID="I25" NAME="I25"><B>File Close</B></A></P>
<P>Choosing the <U>F</U>ile, <U>C</U>lose 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.)</P>
<P><A ID="I26" NAME="I26"><B>File Open Workspace</B></A></P>
<P>Use this item to open a workspace. (You can use <U>F</U>ile, <U>O</U>pen and change the file type to Project Workspace, but using <U>F</U>ile, Open <U>W</U>orkspace is quicker.)</P>
<P><A ID="I27" NAME="I27"><B>File Close Workspace</B></A></P>
<P>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.</P>
<P><A ID="I28" NAME="I28"><B>File Save (Ctrl+S)</B></A></P>
<P>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.</P>
<P><A ID="I29" NAME="I29"><B>File Save As</B></A></P>
<P>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.</P>
<P><A ID="I30" NAME="I30"><B>File Save All</B></A></P>
<P>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.)</P>
<P><A ID="I31" NAME="I31"><B>File Rename</B></A></P>
<P>Use this item to change the name of a file without leaving a copy under the old name.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -