📄 apc.htm
字号:
</BLOCKQUOTE>
<P>This method of editing dialog boxes is one of the reasons for the name <I>Visual
C++</I>. 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, like any other sizable window. Before Visual C++ was released,
the process involved coding and pixel counting and took many minutes rather than
just a few seconds. This visual approach to dialog box building made Windows programming
accessible to many more programmers.</P>
<P><A HREF="javascript:popUp('xcuvc04.gif')"><B>FIG. C.4</B></A><B> </B><I>Dialog
boxes receive information from the user.</I></P>
<H3><I></I></H3>
<H3><A NAME="Heading6"></A>Icons</H3>
<P><I>Icons</I> 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. When an MDI window is minimized within your application, the minimized window
is represented by an icon. Figure C.5 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.</P>
<P>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.</P>
<P>
<H3><A NAME="Heading7"></A>Menus</H3>
<P>With <I>menus, </I>users can tell your program what to do. <I>Keyboard shortcuts</I>
(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 C.6 shows a menu displayed in the ResourceView. Choose View, Properties
to display the Menu \revised Properties box for the menu item. Every menu item has
the following three components:</P>
<P><A HREF="javascript:popUp('xcuvc05.gif')"><B>FIG. C.5</B></A><B> </B><I>Icons
represent your application and its documents.</I></P>
<P>
<UL>
<LI><I>Resource ID</I>. This uniquely identifies this menu item. Accelerators and
toolbar buttons are linked to resource IDs. The convention is to build the ID from
the menu choices that lead to the item. In Figure C.6, the resource ID is ID_FILE_OPEN.
<P>
<LI><I>Caption</I>. This is the text that appears for a menu choice. In Figure C.6,
the caption is &Open...\tCtrl+O. The & means that the O will appear underlined,
and the menu item can be selected by typing <B>O </B>when the menu is displayed.
The \t is a tab, and the Ctrl+O is the accelerator for this menu item, as defined
in Figure C.3.
<P>
<LI><I>Prompt</I>. A prompt appears in the status bar when the highlight is on the
menu item or the cursor is over the associated toolbar button. In Figure C.6, the
prompt is Open an existing document\nOpen. Only the portion before the newline (\n)
is displayed in the status bar. The second part of the prompt, Open, is the text
for the ToolTip that appears if the user pauses the mouse over a toolbar button with
this resource ID. All this functionality is provided for you automatically by the
framework of Visual C++ and MFC.
</UL>
<H3><A NAME="Heading8"></A>The String Table</H3>
<P>The <I>string table</I> 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.</P>
<P>Figure C.7 shows the string table for a sample application. To change a string,
open the String Table Properties dialog box and change the caption. Strings cannot
be changed within the main working area.</P>
<P><A HREF="javascript:popUp('xcuvc06.gif')"><B>FIG. C.6</B></A><B> </B><I>Your application
receives commands through menus.</I></P>
<P><A HREF="javascript:popUp('xcuvc07.gif')"><B>FIG. C.7</B></A><B> </B><I>The string
table stores all the prompts and text in your application.</I></P>
<H3><I></I></H3>
<H3><A NAME="Heading9"></A>Toolbars</H3>
<P><I>Toolbars</I> 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.</P>
<P>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 C.8 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.</P>
<P><A HREF="javascript:popUp('xcuvc08.gif')"><B>FIG. C.8</B></A><B> </B><I>Toolbar
buttons are associated with menu items through a resource ID.</I></P>
<P>
<H3><A NAME="Heading10"></A>Version Information</H3>
<P>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.</P>
<P>When you create an application with AppWizard, version information like that in
Figure C.9 is generated for you automatically. Before attempting to change any of
it, make sure you understand how installation programs use it.</P>
<P><A HREF="javascript:popUp('xcuvc09.gif')"><B>FIG. C.9</B></A><B> </B><I>Version
information is used by install programs.</I></P>
<H2><I></I></H2>
<H2><A NAME="Heading11"></A>Looking at Your Code, Arranged by Class</H2>
<P>The ClassView shows the classes in your application. Under each class, the member
variables and functions are shown, as demonstrated in Figure C.10. 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, whereas private
members have a padlock.</P>
<P><A HREF="javascript:popUp('xcuvc10.gif')"><B>FIG. C.10</B></A><B> </B><I>The ClassView
shows the functions and variables in each class in your application.</I></P>
<P>Double-clicking a function name opens the source for that function in the main
working area, as shown in Figure C.10. Double-clicking a variable name opens the
file in which the variable is declared.</P>
<P>Right-clicking a classname opens a shortcut menu, shown in Figure C.11, with these
items:</P>
<UL>
<LI><I>Go to Definition</I>. Opens the header (.h) file at the definition of this
class.
<P>
<LI><I>Go to Dialog Editor.</I> For classes associated with a dialog box, opens the
dialog box in the resource editor.
<P>
<LI><I>Add Member Function</I>. Opens the Add Member Function dialog box shown in
Figure C.12. This adds a declaration of the function to the header file, and the
stub of a definition to the source file.
</UL>
<P><A HREF="javascript:popUp('xcuvc11.gif')"><B>FIG. C.11</B></A><B> </B><I>Common
commands related to classes are on the ClassView shortcut menu for a class.</I></P>
<P><I><BR>
</I><A HREF="javascript:popUp('xcuvc12.gif')"><B>FIG. C.12</B></A><B> </B><I>Never
again forget to add part of a function declaration or definition when you use the
Add Member Function shortcut.</I></P>
<UL>
<LI><I>Add Member Variable</I>. Opens the Add Member Variable dialog box shown in
Figure C.13. This adds a declaration of the variable to the header file.
</UL>
<P><A HREF="javascript:popUp('xcuvc13.gif')"><B>FIG. C.13</B></A><B> </B><I>Simplify
adding member variables with this shortcut.</I></P>
<P>
<UL>
<LI><I>Add Virtual Function</I>. Opens the New Virtual Override dialog box, discussed
in Chapter 3, "Messages and Commands."
<P>
<LI><I>Add Windows Message Handler</I>. Opens the New Windows Message and Event Handlers
dialog box, discussed in Chapter 3.
<P>
<LI><I>References</I>. Opens a list of the places where the classname is mentioned
within your application. Typically the classname occurs in declarations of instances
of the class, but this will also find places where the classname is passed as a parameter
to a function or macro.
<P>
<LI><I>Derived Classes</I>. Opens a list of all the member functions and member variables
of this class, a list of other classes that use this class as a base class, and the
references information.
<P>
<LI><I>Base Classes</I>. Opens a list of all the member functions and member variables
of this class, a list of the base classes of this class, and the references information.
<P>
<LI><I>Add to Gallery</I>. Adds this class to the Component Gallery, discussed in
Chapter 25, "Achieving Reuse with the Gallery and Your Own AppWizards."
<P>
<LI><I>New Folder</I>. Creates a folder you can drag classes into. This helps to
organize projects with large numbers of classes.
<P>
<LI><I>Group by Access</I>. Rearranges the order of the list. By default, functions
are listed in alphabetical order, followed by data members in alphabetical order.
With this option toggled on, functions come first (public, then protected, then private
functions, alphabetically in each section) followed by data members (again public,
then protected, then private data members, alphabetically in each section).
<P>
<LI><I>Docking View</I>. Keeps the project workspace window docked at the side of
the main working area or undocks it if it was docked.
<P>
<LI><I>Hide</I>. Hides the project workspace window. To redisplay it, choose View,
Workspace.
<P>
<LI><I>Properties</I>. Displays the properties of the class (name, base class).
</UL>
<BLOCKQUOTE>
<P>
<HR>
<strong>TIP:</strong> 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.
<HR>
</BLOCKQUOTE>
<P>Right-clicking the name of a member function opens a substantial shortcut menu,
with the following menu items:</P>
<UL>
<LI><I>Go To Definition</I>. Opens the source (.cpp) file at the code for this function.
<P>
<LI><I>Go To Declaration</I>. Opens the header (.h) file at the declaration of this
function.
<P>
<LI><I>Delete</I>. Removes the function from the class.
<P>
<LI><I>Set Breakpoint</I>. Sets a breakpoint. Breakpoints are discussed in Appendix
D, "Debugging."
<P>
<LI><I>References</I>. Opens a list of the places where the function is called within
your application.
<P>
<LI><I>Calls</I>. Displays a collapsible and expandable outline of all the functions
that this function calls. Figure C.14 shows a sample Call Graph window.
</UL>
<P><A HREF="javascript:popUp('xcuvc14.gif')"><B>FIG. C.14</B></A><B> </B><I>The Call
Graph window lists all the functions that your function calls, and all the functions
they call, and so on.</I></P>
<UL>
<LI><I>Called By</I>. Displays a Callers Graph listing the functions this function
is called by.
<P>
<LI><I>New Folder</I>. Creates a folder you can drag classes into. This helps organize
projects with large numbers of classes.
<P>
<LI><I>Group by Access</I>. Rearranges the order of the list. By default, functions
are listed in alphabetical order, followed by data members in alphabetical order.
With this option toggled on, functions come first (public, then protected, then private
functions, alphabetically in each section) followed by data members (again public,
then protected, then private data members, alphabetically in each section).
<P>
<LI><I>Docking View</I>. Keeps the workspace window docked at the side of the main
working area.
<P>
<LI><I>Hide</I>. Hides the workspace window. To redisplay it, choose View, Workspace.
<P>
<LI><I>Properties</I>. Displays the properties of the function (name, return type,
parameters).
</UL>
<P>Right-clicking the name of a member variable opens a shortcut menu with less menu
items. The items are as follows:</P>
<UL>
<LI><I>Go To Definition</I>. Opens the header (.h) file at the declaration of this
variable.
<P>
<LI><I>References</I>. Opens a list of the places where the variable is used within
your application.
<P>
<LI><I>New Folder</I>. Creates a folder you can drag classes into. This helps organize
projects with large numbers of classes.
<P>
<LI><I>Group by Access</I>. Rearranges the order of the list. By default, functions
are listed in alphabetical order, followed by data members in alphabetical order.
With this option toggled on, functions come first (public, then protected, then private
functions, alphabetically in each section) followed by data members (again public,
then protected, then private data members, alphabetically in each section).
<P>
<LI><I>Docking View</I>. Keeps the workspace window docked at the side of the main
working area.
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -