📄 ch01.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Teach Yourself Visual C++® 5 in 24 Hours -- Hour 1 -- Introducing Visual C++ 5</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<CENTER>
<H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
<FONT COLOR="#000077">Teach Yourself Visual C++® 5 in 24 Hours</FONT></H1>
</CENTER>
<CENTER>
<P><A HREF="../fm/fm.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch02/ch02.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A>
<HR>
</CENTER>
<CENTER>
<H1><FONT COLOR="#000077">- Hour 1 -<BR>
Introducing Visual C++ 5</FONT></H1>
</CENTER>
<P>Welcome to Hour 1 of <I>Teach Yourself Visual C++ 5 in 24 Hours</I>! Visual C++
is an exciting subject, and this first hour gets you right into the basic features
of the new Visual C++ 5 compiler and starts you off building some basic programs.</P>
<P>These are the highlights of this hour:
<UL>
<LI>A short overview of the Visual C++ environment and how to work in it<BR>
<BR>
<LI>How to compile a simple console-mode program<BR>
<BR>
<LI>How to use AppWizard to create a Windows application
</UL>
<H2><FONT COLOR="#000077"><B>Exploring Visual C++ 5</B></FONT></H2>
<P>Visual C++ 5 is the latest C++ compiler from Microsoft, continuing a long line
of Microsoft tools for Windows development. The Visual C++ package contains more
than a compiler; it also contains all the libraries, examples, and documentation
needed to create applications for Windows 95 and Windows NT.</P>
<P>Windows development tools have certainly come a long way since the earliest C
and C++ compilers for Windows. By combining into a single tool all the resources
required to build Windows applications, Microsoft has made it much easier for you
to learn to build applications.
<H3><FONT COLOR="#000077"><B>The Visual C++ Environment</B></FONT></H3>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>An <I>IDE</I>, or <I>Integrated
Development Environment</I>, is a program that hosts the compiler, debugger, and
application-building tools.</P>
<P>The central part of the Visual C++ package is <I>Developer Studio</I>, the Integrated
Development Environment (IDE), shown in Figure 1.1. Developer Studio is used to integrate
the development tools and the Visual C++ compiler. You can create a Windows program,
scan through an impressive amount of online help, and debug a program without leaving
Developer Studio.</P>
<P><A NAME="01"></A><A HREF="01.htm"><B>Figure 1.1.</B> </A><I><BR>
Using Developer Studio to create a Windows program.</I></P>
<P>Visual C++ and Developer Studio make up a fully integrated environment that makes
it very easy to create Windows programs. By using the tools and wizards provided
as part of Developer Studio, along with the MFC class library, you can create a program
in just a few minutes.</P>
<P>Many of the programs used as examples in this book require less than a page of
additional source code. However, these programs use the thousands of lines of source
code that are part of the MFC class library. They also take advantage of AppWizard
and ClassWizard, two of the Developer Studio tools that manage your project for you.
<H3><FONT COLOR="#000077"><B>Developer Studio Tools</B></FONT></H3>
<P>Once upon a time, Windows programmers used simple text editors and tools that
were hosted on MS-DOS to create their Windows programs. Developing a program under
those conditions was tedious and error-prone. Times have definitely changed; Developer
Studio includes a number of tools that you might once have paid extra to purchase.
<UL>
<LI>An integrated editor offers drag-and-drop and syntax highlighting as two of its
major features. You can configure the Developer Studio editor to emulate the keystroke
commands used by two popular programmer's editors, Brief and Epsilon.<BR>
<BR>
<LI>A resource editor is used to create Windows resources, such as bitmaps, icons,
dialog boxes, and menus.<BR>
<BR>
<LI>An integrated debugger enables you to run programs and check for errors. Because
the debugger is part of Developer Studio, it's easy to find and correct bugs. If
you find a programming error while debugging, you can correct the source code, recompile,
and restart the debugger.
</UL>
<P>Developer Studio also features an online help system, which can be used to get
context-sensitive help for all of the tools included in Developer Studio, as well
as detailed help on the C++ language, the Windows programming interface, and the
MFC class library.
<H3><FONT COLOR="#000077"><B>Developer Studio Wizards</B></FONT></H3>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>Wizard</I> is a tool
that helps guide you through a series of steps.</P>
<P>In addition to tools that are used for debugging, editing, and creating resources,
Developer Studio includes several wizards that are used to simplify developing your
Windows programs. The most commonly used ones are
<UL>
<LI><I>AppWizard</I> (also referred to in some screens as MFC AppWizard) is used
to create the basic outline of a Windows program. Three types of programs are supported
by AppWizard: single document and multiple document applications based on the Document/View
architecture and dialog box-based programs, in which a dialog box serves as the application's
main window. Later in this hour, you will use AppWizard to create a simple program.<BR>
<BR>
<LI><I>ClassWizard</I> is used to define the classes in a program created with AppWizard.
Using ClassWizard, you can add classes to your project. You can also add functions
that control how messages received by each class are handled. ClassWizard also helps
manage controls that are contained in dialog boxes by enabling you to associate an
MFC object or class member variable with each control. You will learn more about
ClassWizard in Hour 4, "Dialog Boxes and C++ Classes."<BR>
<BR>
<LI><I>ActiveX ControlWizard</I> is used to create the basic framework of an ActiveX
control. An ActiveX control is a customized control that supports a defined set of
interfaces and is used as a reusable component. ActiveX controls replace Visual Basic
controls, or VBXs, which were used in 16-bit versions of Windows. ActiveX controls
are used in Hour 20, "Using ActiveX Controls," and you will build an ActiveX
control in Hour 24, "Creating ActiveX Controls."
</UL>
<H3><FONT COLOR="#000077"><B>MFC Libraries</B></FONT></H3>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>library</I> is a collection
of source code or compiled code that you can reuse in your programs. Libraries are
available from compiler vendors such as Microsoft, as well as from third parties.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>Visual C++ 5 includes Version
5.0 of <I>MFC</I>, the Microsoft Foundation Classes, a class library that makes programming
for Windows much easier.</P>
<P>By using the MFC classes when writing your programs for Windows, you can take
advantage of a large amount of source code that has been written for you. This enables
you to concentrate on the important parts of your code rather than worry about the
details of Windows programming.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A recent addition to the
C++ standard is the <I>Standard C++ Library</I>. This library includes a set of classes
that were known as the Standard Template Library, or STL, during the standardization
process. Unlike the MFC class library, which is used primarily for Windows programming,
the standard C++ library is used for general-purpose programming.
<H2><FONT COLOR="#000077"><B>Starting Developer Studio</B></FONT></H2>
<P>To start Developer Studio, click the Developer Studio icon located in the Visual
C++ folder. To get to the Visual C++ folder, click the Start button on the taskbar
and then select Programs. One of the items in the Programs folder is Microsoft Visual
C++ 5.0. Figure 1.2 shows a start menu tree opened to the Microsoft Developer Studio
icon.</P>
<P><A NAME="02"></A><A HREF="02.htm"><B>Figure 1.2.</B></A> <BR>
<I>Starting Developer Studio from the Start button.</I></P>
<P>Developer Studio initially displays two windows:
<UL>
<LI>A Project Workspace window located on the left side; this window contains a table
of online help contents<BR>
<BR>
<LI>A Document window on the right side; this window contains the documentation home
page
</UL>
<P>Developer Studio also includes a rich set of menus, toolbars, and other user interface
features, as shown in Figure 1.3.</P>
<P><A NAME="03"></A><A HREF="03.htm"><B>Figure 1.3.</B> </A><BR>
<I>Developer Studio when first started.</I>
<H3><FONT COLOR="#000077"><B>Exploring InfoViewer</B></FONT></H3>
<P>InfoViewer is the online help system integrated into Developer Studio. InfoViewer
is also compatible with the Microsoft Developer Network CD-ROM, enabling you to search
that database for information.
<BLOCKQUOTE>
<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>Time Saver:</B></FONT><B> </B>Usually, the indexes
used by the InfoViewer are copied to your hard disk and the actual database remains
on the CD-ROM. If you would like to speed up InfoViewer, run Visual C++ setup again
and install InfoViewer to the hard disk.
<HR>
</BLOCKQUOTE>
<H4><FONT COLOR="#000077">Using Dockable Windows in Developer Studio</FONT></H4>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>Many of the views displayed
by Developer Studio are <I>dockable</I>, which means they can be attached to the
edge of the Developer Studio workspace, where they remain until undocked.</P>
<P>The Project Workspace window shown in Figure 1.3 is an example of a dockable view.
To "undock" a dockable window, double-click the window's edge. To dock
a floating window, move it to the edge of the workspace. If it is a dockable window,
it docks itself. If you want to move a dockable window close to the edge of a workspace
without docking, press the Ctrl key on the keyboard when moving the window.
<H4><FONT COLOR="#000077">Getting Context-Sensitive Help</FONT></H4>
<P>To get context-sensitive help from InfoViewer, press F1. You select a topic based
on the current window and cursor position, and you see the InfoViewer window, containing
context-sensitive help. If you press F1 while editing a source file, help is provided
for the word under the cursor. If there is more than one possible help topic, you
see a list of choices.
<H3><FONT COLOR="#000077"><B>The Visual C++ Editor</B></FONT></H3>
<P>Developer Studio includes a sophisticated editor as one of its tools. The editor
is integrated with the other parts of Developer Studio; files are edited in a Developer
Studio child window.</P>
<P>You use the Developer Studio editor to edit C++ source files that will be compiled
into Windows programs. The editor supplied with Developer Studio is similar to a
word processor, but instead of fancy text-formatting features, it has features that
make it easy to write source code.</P>
<P>You can use almost any editor to write C++ source code, but there are several
reasons to consider using the editor integrated with Developer Studio. The editor
includes many features that are found in specialized programming editors.
<UL>
<LI>Automatic syntax highlighting colors keywords, comments, and other source code
in different colors.<BR>
<BR>
<LI>Automatic "smart" indenting helps line up your code into easy-to-read
columns.<BR>
<BR>
<LI>Emulation for keystrokes used by other editors helps if you are familiar with
editors such as Brief and Epsilon.<BR>
<BR>
<LI>Integrated keyword help enables you to get help on any keyword, MFC class, or
Windows function just by pressing F1.<BR>
<BR>
<LI>Drag-and-drop editing enables you to move text easily by dragging it with the
mouse.<BR>
<BR>
<LI>Integration with the compiler's error output helps you step through the list
of errors reported by the compiler and positions the cursor at every error. This
enables you to make corrections easily without leaving Developer Studio.
</UL>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -