⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch01.htm

📁 VC 21天 学习VC 的好东西
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">

<!--

function popUp(pPage) {
 var fullURL = document.location;
 var textURL = fullURL.toString();
 var URLlen = textURL.length;
 var lenMinusPage = textURL.lastIndexOf("/");
 lenMinusPage += 1;
 var fullPath = textURL.substring(0,lenMinusPage);
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '</head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + fullPath + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
 // Johnny Jackson 4/28/98
 }

//-->
                                                                
</SCRIPT>
<!--<link rel="stylesheet" href="../../../../includes/stylesheets/ebooks.css">-->

	<META NAME="GENERATOR" Content="Symantec Visual Page Mac 1.1.1">
	<TITLE>Teach Yourself Visual C++ 6 in 21 Days -- Ch 1 -- The Visual C++ Development Environment--Building Your First Visual C++ Application</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<H1 ALIGN="CENTER"><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM"
BORDER="0"><BR>
Teach Yourself Visual C++ 6 in 21 Days</H1>
<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>
<H1 ALIGN="CENTER">- 1 -<BR>
The Visual C++ Development Environment--Building Your First Visual C++ Application</H1>
<H1></H1>

<UL>
	<LI><A HREF="#Heading1">The Visual C++ Development Environment</A>
	<UL>
		<LI><A HREF="#Heading2">The Output Pane</A>
		<LI><A HREF="#Heading3">The Editor Area</A>
		<LI><A HREF="#Heading4">Menu Bars</A>
		<LI><A HREF="#Heading5">Rearranging the Developer Studio Environment</A>
	</UL>
	<LI><A HREF="#Heading6">Starting Your First Project</A>
	<UL>
		<LI><A HREF="#Heading7">Creating the Project Workspace</A>
		<LI><A HREF="#Heading8">Using the Application Wizard to Create the Application Shell</A>
	</UL>
	<LI><A HREF="#Heading9">Designing Your Application Window</A>
	<LI><A HREF="#Heading10">Adding Code to Your Application</A>
	<LI><A HREF="#Heading11">Finishing Touches</A>
	<UL>
		<LI><A HREF="#Heading12">Creating the Dialog Box Icon</A>
		<LI><A HREF="#Heading13">Adding Maximize and Minimize Buttons</A>
	</UL>
	<LI><A HREF="#Heading14">Summary</A>
	<LI><A HREF="#Heading15">Q&amp;A</A>
	<LI><A HREF="#Heading16">Workshop</A>
	<UL>
		<LI><A HREF="#Heading17">Quiz</A>
		<LI><A HREF="#Heading18">Exercise</A>
	</UL>
</UL>

<P>
<HR SIZE="4">
<BR>
Welcome to <I>Sams</I> <I>Teach Yourself Visual C++ 6 in 21 Days</I>. Over the next
three weeks, you will learn how to build a wide variety of applications with Microsoft's
Visual C++. What's even better is that you will learn how to create these types of
applications by actually building them yourself. As you read this book, you will
be gaining actual programming experience using Visual C++. So let's get started!</P>
<P>Today, your focus will be on learning about the Visual C++ development environment
and some of the tools that it provides for building applications. Although Visual
C++ provides more tools than you would probably use in any one application development
effort--even more than you could possibly learn to use in a single day--I limit the
focus to the primary tools that you will use throughout this book, as well as in
just about every application you build with Visual C++. Today, you'll learn about
the following:</P>

<UL>
	<LI>The primary areas of the Visual C++ development environment
	<P>
	<LI>The Application Wizard--how you can use it to build the basic infrastructure
	for your applications
	<P>
	<LI>The Dialog Painter--how you can use it to paint dialog windows, much in the same
	way that you can build windows with Visual Basic, PowerBuilder, or Delphi
	<P>
	<LI>The Class Wizard--how you can use it to attach functionality to your application
	windows
</UL>

<H2><A NAME="Heading1"></A>The Visual C++ Development Environment</H2>
<P>Before you begin your quick tour around the Visual C++ development environment,
you should start Visual C++ on your computer so that you can see firsthand how each
of the areas are arranged and how you can change and alter that arrangement yourself.</P>
<P>After Developer Studio (the Microsoft Visual development environment) starts,
you see a window that looks like Figure 1.1. Each of the areas has a specific purpose
in the Developer Studio environment. You can rearrange these areas to customize the
Developer Studio environment so that it suits your particular development needs.</P>
<H3>The Workspace</H3>
<P>When you start Visual C++ for the first time, an area on the left side of Developer
Studio looks like it is taking up a lot of real estate and providing little to show
for it. This area is known as the workspace, and it is your key to navigating the
various pieces and parts of your development projects. The workspace allows you to
view the parts of your application in three different ways:</P>

<UL>
	<LI>Class View allows you to navigate and manipulate your source code on a C++ class
	level.
	<P>
	<LI>Resource View allows you to find and edit each of the various resources in your
	application, including dialog window designs, icons, and menus.
	<P>
	<LI>File View allows you to view and navigate all the files that make up your appli-cation.
</UL>

<P><A HREF="javascript:popUp('01fig01.gif')"><B>FIGURE 1.1.</B></A><B> </B><I>The
Visual C++ opening screen.</I></P>
<P>
<H3><A NAME="Heading2"></A>The Output Pane</H3>
<P>The Output pane might not be visible when you start Visual C++ for the first time.
After you compile your first application, it appears at the bottom of the Developer
Studio environment and remains open until you choose to close it. The Output pane
is where Developer Studio provides any information that it needs to give you; where
you see all the compiler progress statements, warnings, and error messages; and where
the Visual C++ debugger displays all the variables with their current values as you
step through your code. After you close the Output pane, it reopens itself when Visual
C++ has any message that it needs to display for you.</P>
<P>
<H3><A NAME="Heading3"></A>The Editor Area</H3>
<P>The area on the right side of the Developer Studio environment is the editor area.
This is the area where you perform all your editing when using Visual C++, where
the code editor windows display when you edit C++ source code, and where the window
painter displays when you design a dialog box. The editor area is even where the
icon painter displays when you design the icons for use in your applications. The
editor area is basically the entire Developer Studio area that is not otherwise occupied
by panes, menus, or toolbars.</P>
<P>
<H3><A NAME="Heading4"></A>Menu Bars</H3>
<P>The first time you run Visual C++, three toolbars display just below the menu
bar. Many other toolbars are available in Visual C++, and you can customize and create
your own toolbars to accommodate how you best work. The three toolbars that are initially
open are the following:</P>

<UL>
	<LI>The Standard toolbar contains most of the standard tools for opening and saving
	files, cutting, copying, pasting, and a variety of other commands that you are likely
	to find useful.
</UL>

<P>The WizardBar toolbar enables you to perform a number of Class Wizard actions
without opening the Class Wizard.</P>

<UL>
	<LI>The Build minibar provides you with the build and run commands that you are most
	likely to use as you develop and test your applications. The full Build toolbar also
	lets you switch between multiple build configurations (such as between the Debug
	and Release build configurations).
</UL>

<H3><A NAME="Heading5"></A>Rearranging the Developer Studio Environment</H3>
<P>The Developer Studio provides two easy ways to rearrange your development environment.
The first is by right-clicking your mouse over the toolbar area. This action opens
the pop-up menu shown in Figure 1.2, allowing you to turn on and off various toolbars
and panes.</P>
<P><A HREF="javascript:popUp('01fig02.gif')"><B>FIGURE 1.2.</B></A><B> </B><I>Toolbar
on and off menu.</I></P>
<P>Another way that you can easily rearrange your development environment is to grab
the double bars at the left end of any of the toolbars or panes with the mouse. You
can drag the toolbars away from where they are currently docked, making them floating
toolbars, as in Figure 1.3. You can drag these toolbars (and panes) to any other
edge of the Developer Studio to dock them in a new spot. Even when the toolbars are
docked, you can use the double bars to drag the toolbar left and right to place the
toolbar where you want it to be located.</P>
<P><A HREF="javascript:popUp('01fig03.gif')"><B>FIGURE 1.3.</B></A><B> </B><I>Example
of a floating minibar.</I></P>


<BLOCKQUOTE>
	<P>
<HR>
<STRONG>NOTE:</STRONG> On the workspace and Output panes, the double bars that you
	can use to drag the pane around the Developer Studio environment might appear on
	the top of the pane or on the left side, depending on how and where the pane is docked.
	
<HR>


</BLOCKQUOTE>

<H2><A NAME="Heading6"></A>Starting Your First Project</H2>
<P>For your first Visual C++ application, you are going to create a simple application
that presents the user with two buttons, as in Figure 1.4. The first button will
present the user with a simple greeting message, shown in Figure 1.5, and the second
button will close the application. In building this application, you will need to
do the following things:</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Create a new project workspace.
	<P>
	<DT></DT>
	<DD><B>2. </B>Use the Application Wizard to create the application framework.
	<P>
	<DT></DT>
	<DD><B>3. </B>Rearrange the dialog that is automatically created by the Application
	Wizard to resemble how you want the application to look.
	<P>
	<DT></DT>
	<DD><B>4. </B>Add the C++ code to show the greeting to the user.
	<P>
	<DT></DT>
	<DD><B>5. </B>Create a new icon for the application.
	<P>
</DL>

<P><A HREF="javascript:popUp('01fig04.gif')"><B>FIGURE 1.4.</B></A><B> </B><I>Your
first Visual C++ application.</I></P>

<P><A HREF="javascript:popUp('01fig05.gif')"><B>FIGURE 1.5.</B></A><B> </B><I>If
the user clicks the first button, a simple greeting is shown.</I></P>

<P><I></I>
<H3><A NAME="Heading7"></A>Creating the Project Workspace</H3>
<P>Every application development project needs its own project workspace in Visual
C++. The workspace includes the directories where the application source code is
kept, as well as the directories where the various build configuration files are
located. You can create a new project workspace by following these steps:</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Select File | New. This opens the New Wizard shown in Figure 1.6.
	<P>
</DL>

<P><A HREF="javascript:popUp('01fig06.gif')"><B>FIGURE 1.6.</B></A><B> </B><I>The
New Wizard.</I></P>

<DL>
	<DT><I></I></DT>
	<DD><B>2. </B>On the Projects tab, select MFC AppWizard (exe).
	<P>
	<DT></DT>
	<DD><B>3. </B>Type a name for your project, such as Hello, in the Project Name field.
	<P>
	<DT></DT>
	<DD><B>4. </B>Click OK. This causes the New Wizard to do two things: create a project
	directory (specified in the Location field) and then start the AppWizard.
	<P>
</DL>

<H3><A NAME="Heading8"></A>Using the Application Wizard to Create the Application
Shell</H3>
<P>The AppWizard asks you a series of questions about what type of application you
are building and what features and functionality you need. It uses this information
to create a shell of an application that you can immediately compile and run. This
shell provides you with the basic infrastructure that you need to build your application
around. You will see how this works as you follow these steps:</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>In Step 1 of the AppWizard, specify that you want to create a Dialog-based
	application. Click Next at the bottom of the wizard.
	<P>
	<DT></DT>
	<DD><B>2. </B>In Step 2 of the AppWizard, the wizard asks you about a number of features
	that you can include in your application. You can uncheck the option for including
	support for ActiveX controls if you will not be using any ActiveX controls in your
	application. Because you won't be using any ActiveX controls in today's application,
	go ahead and uncheck this box.
	<P>
	<DT></DT>
	<DD><B>3. </B>In the field near the bottom of the wizard, delete the project name
	(Hello) and type in the title that you want to appear in the title bar of the main
	application window, such as <B>My First Visual C++ Application</B>. Click Next at
	the bottom of the wizard.
	<P>
	<DT></DT>
	<DD><B>4. </B>In Step 3 of the AppWizard, leave the defaults for including source
	file comments and using the MFC library as a DLL. Click Next at the bottom of the
	wizard to proceed to the final AppWizard step.
	<P>
	<DT></DT>
	<DD><B>5. </B>The final step of the AppWizard shows you the C++ classes that the
	AppWizard will create for your application. Click Finish to let AppWizard generate
	your application shell.
	<P>
	<DT></DT>
	<DD><B>6. </B>Before AppWizard creates your application shell, it presents you with
	a list of what it is going to put into the application shell, as shown in Figure
	1.7, based on the options you selected when going through the AppWizard. Click OK
	and AppWizard generates your application.
	<P>
</DL>

<P><A HREF="javascript:popUp('01fig07.gif')"><B>FIGURE 1.7.</B></A><B> </B><I>The
New Project Information screen.</I></P>

<UL>
	<LI><B>7. </B>After the AppWizard generates your application shell, you are returned
	to the Developer Studio environment. You will notice that the workspace pane now
	presents you with a tree view of the classes in your application shell, as in Figure
	1.8. You might also be presented with the main dialog window in the editor area of

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -