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

📄 ch01.htm

📁 Learning language of Visual C++6
💻 HTM
📖 第 1 页 / 共 5 页
字号:
1.18.</P>
<P><A HREF="javascript:popUp('01uvc17.gif')"><B>FIG. 1.17</B></A><B> </B><I>Step
3 of the AppWizard process for a dialog-based application deals with comments and
the MFC library.</I></P>
<P><A HREF="javascript:popUp('01uvc18.gif')"><B>FIG. 1.18</B></A><B> </B><I>Step
4 of the AppWizard process for a dialog-based application gives you a chance to adjust
filenames and classnames.</I></P>
<P>In this step you can change the names AppWizard chooses for files and classes.
This is rarely a good idea because it will confuse people who maintain your code
if the filenames can't be easily distinguished from the classnames, and vice versa.
If you realize after looking at this dialog that you made a poor choice of project
name, use Back to move all the way back to the New Project Workspace dialog, change
the name, click Create, and then use Next to return to this dialog. Click Finish
to see the summary of the files and classes to be created, similar to that in Figure
1.19.</P>
<P>If any information on this dialog isn't what you wanted, click Cancel and then
use Back to move to the appropriate step and change your choices. When the information
is right, click OK and watch as the application is created.</P>
<P>To try it yourself, create an empty dialog-based application yourself, call it
<I>FirstDialog</I>, and accept the defaults for each step of AppWizard. When it's
complete, choose Build, Build to compile and link the application. Choose Build,
Execute to see it in action. Figure 1.20 shows the empty dialog-based application
running.</P>
<P><A HREF="javascript:popUp('01uvc19.gif')"><B>FIG. 1.19</B></A><B> </B><I>AppWizard
confirms the files and classes before creating them.</I></P>
<P><A HREF="javascript:popUp('01uvc20.gif')"><B>FIG. 1.20</B></A><B> </B><I>A starter
dialog application includes a reminder of the work ahead of you.</I></P>
<P>Clicking the OK or Cancel button, or the X in the top-right corner, makes the
dialog disappear. Clicking the system menu in the top-left corner gives you a choice
of Move, Close, or About. Figure 1.21 shows the About box that was generated for
you.</P>
<P><A HREF="javascript:popUp('01uvc21.gif')"><B>FIG. 1.21</B></A><B> </B><I>The same
About box is generated for SDI, MDI, and dialog-based applications.</I></P>
<H2><A NAME="Heading11"></A>Creating DLLs, Console Applications, and More</H2>
<P>Although most people use AppWizard to create an executable program, it can make
many other kinds of projects. You choose File, New and then the Projects tab, as
discussed at the start of this chapter, but choose a different wizard from the list
on the left of the New dialog box, shown in Figure 1.1. The following are some of
the other projects AppWizard can create:</P>

<UL>
	<LI>ATL COM AppWizard
	<P>
	<LI>Custom AppWizard
	<P>
	<LI>Database Project
	<P>
	<LI>DevStudio Add-In Wizard
	<P>
	<LI>Extended Stored Procedure AppWizard
	<P>
	<LI>ISAPI Extension Wizard
	<P>
	<LI>Makefile
	<P>
	<LI>MFC ActiveX ControlWizard
	<P>
	<LI>MFC AppWizard (dll)
	<P>
	<LI>Utility Project
	<P>
	<LI>Win32 Application
	<P>
	<LI>Win32 Console Application
	<P>
	<LI>Win32 Dynamic Link Library
	<P>
	<LI>Win32 Static Library
</UL>

<P>These projects are explained in the following sections.</P>
<P>
<H3><A NAME="Heading12"></A>ATL COM AppWizard</H3>
<P>ATL is the Active Template Library, and it's used to write small ActiveX controls.
It's generally used by developers who have already mastered writing MFC ActiveX controls,
though an MFC background is not required to learn ATL. Chapter 17 introduces important
control concepts while demonstrating how to build an MFC control; Chapter 21, &quot;The
Active Template Library,&quot; teaches you ATL.</P>
<P>
<H3><A NAME="Heading13"></A>Custom AppWizard</H3>
<P>Perhaps you work in a large programming shop that builds many applications. Although
AppWizard saves a lot of time, your programmers may spend a day or two at the start
of each project pasting in your own <I>boilerplate</I>, which is material that is
the same in every one of your projects. You may find it well worth your time to build
a Custom AppWizard, a wizard of your very own that puts in your boilerplate as well
as the standard MFC material. After you have done this, your application type is
added to the list box on the left of the Projects tab of the New dialog box shown
in Figure 1.1. Creating and using Custom AppWizards is discussed in Chapter 25, &quot;Achieving
Reuse with the Gallery and Your Own AppWizards.&quot;</P>
<P>
<H3><A NAME="Heading14"></A>Database Project</H3>
<P>If you have installed the Enterprise Edition of Visual C++, you can create a database
project. This is discussed in Chapter 23, &quot;SQL and the Enterprise Edition.&quot;</P>
<P>
<H3><A NAME="Heading15"></A>DevStudio Add-In Wizard</H3>
<P>Add-ins are like macros that automate Developer Studio, but they are written in
C++ or another programming language; macros are written in VBScript. They use automation
to manipulate Developer Studio.</P>
<P>
<H3><A NAME="Heading16"></A>ISAPI Extension Wizard</H3>
<P>ISAPI stands for Internet Server API and refers to functions you can call to interact
with a running copy of Microsoft Internet Information Server, a World Wide Web server
program that serves out Web pages in response to client requests. You can use this
API to write DLLs used by programs that go far beyond browsing the Web to sophisticated
automatic information retrieval. This process is discussed in Chapter 18.</P>
<P>
<H3><A NAME="Heading17"></A>Makefile</H3>
<P>If you want to create a project that is used with a different make utility than
Developer Studio, choose this wizard from the left list in the New Project Workspace
dialog box. No code is generated. If you don't know what a make utility is, don't
worry--this wizard is for those who prefer to use a standalone tool to replace one
portion of Developer Studio.</P>
<P>
<H3><A NAME="Heading18"></A>MFC ActiveX ControlWizard</H3>
<P><I>ActiveX controls</I> are controls you write that can be used on a Visual C++
dialog, a Visual Basic form, or even a Web page. These controls are the 32-bit replacement
for the VBX controls many developers were using to achieve intuitive interfaces or
to avoid reinventing the wheel on every project. Chapter 17 guides you through building
a control with this wizard.</P>
<P>
<H3><A NAME="Heading19"></A>MFC AppWizard (DLL)</H3>
<P>If you want to collect a number of functions into a DLL, and these functions use
MFC classes, choose this wizard. (If the functions don't use MFC, choose Win32 Dynamic
Link Library, discussed a little later in this section.) Building a DLL is covered
in Chapter 28, &quot;Future Explorations.&quot; AppWizard generates code for you
so you can get started.</P>
<P>
<H3><A NAME="Heading20"></A>Win32 Application</H3>
<P>There are times when you want to create a Windows application in Visual C++ that
doesn't use MFC and doesn't start with the boilerplate code that AppWizard produces
for you. To create such an application, choose the Win32 Application wizard from
the left list in the Projects tab, fill in the name and folder for your project,
and click OK. You are not asked any questions; AppWizard simply creates a project
file for you and opens it. You have to create all your code from scratch and insert
the files into the project.</P>
<P>
<H3><A NAME="Heading21"></A>Win32 Console Application</H3>
<P>A <I>console application</I> looks very much like a DOS application, though it
runs in a resizable window. (Console applications are 32-bit applications that won't
run under DOS, however.) It has a strictly character-based interface with cursor
keys instead of mouse movement. You use the Console API and character-based I/O functions
such as printf() and scanf() to interact with the user. Some very rudimentary boilerplate
code can be generated for you, or you can have just an empty project. Chapter 28
discusses building and using console applications.</P>
<P>
<H3><A NAME="Heading22"></A>Win32 Dynamic Link Library</H3>
<P>If you plan to build a DLL that does not use MFC and does not need any boilerplate,
choose the Win32 Dynamic Link Library option instead of MFC AppWizard (dll). You
get an empty project created right away with no questions.</P>
<P>
<H3><A NAME="Heading23"></A>Win32 Static Library</H3>
<P>Although most code you reuse is gathered into a DLL, you may prefer to use a static
library because that means you don't have to distribute the DLL with your application.
Choose this wizard from the left list in the New Project Workspace dialog box to
create a project file into which you can add object files to be linked into a static
library, which is then linked into your applications.</P>
<P>
<H2><A NAME="Heading24"></A>Changing Your AppWizard Decisions</H2>
<P>Running AppWizard is a one-time task. Assuming you are making a typical application,
you choose File, New; click the Projects tab; enter a name and folder; choose MFC
Application (exe); go through the six steps; create the application starter files;
and then never touch AppWizard again. However, what if you choose not to have online
Help and later realize you should have included it?</P>
<P>AppWizard, despite the name, isn't really magic. It pastes in bits and pieces
of code you need, and you can paste in those very same bits yourself. Here's how
to find out what you need to paste in.</P>
<P>First, create a project with the same options you used in creating the project
whose settings you want to change, and don't add any code to it. Second, in a different
folder create a project with the same name and all the same settings, except the
one thing you want to change (Context-Sensitive Help in this example). Compare the
files, using WinDiff, which comes with Visual C++. Now you know what bits and pieces
you need to add to your full-of-code project to implement the feature you forgot
to ask AppWizard for.</P>
<P>Some developers, if they discover their mistake soon enough, find it quicker to
create a new project with the desired features and then paste their own functions
and resources from the partially built project into the new empty one. It's only
a matter of taste, but after you go through either process for changing your mind,
you probably will move a little more slowly through those AppWizard dialog boxes.</P>
<P>
<H2><A NAME="Heading25"></A>Understanding AppWizard's Code</H2>
<P>The code generated by AppWizard may not make sense to you right away, especially
if you haven't written a C++ program before. You don't need to understand this code
in order to write your own simple applications. Your programs will be better ones,
though, if you know what they are doing, so a quick tour of AppWizard's boilerplate
code is a good idea. You'll see the core of an SDI application, an MDI application,
and a dialog-based application.</P>
<P>You'll need the starter applications FirstSDI, FirstMDI, and FirstDialog, so if
you didn't create them earlier, do so now. If you're unfamiliar with the Developer
Studio interface, glance through Appendix C to learn how to edit code and look at
classes.</P>
<P>
<H3><A NAME="Heading26"></A>A Single Document Interface Application</H3>
<P>An SDI application has menus that the user uses to open one document at a time
and work with that document. This section presents the code that is generated when
you create an SDI application with no database or compound document support, with
a toolbar, a status bar, Help, 3D controls, source file comments, and with the MFC
library as a shared DLL--in other words, when you accept all the AppWizard defaults
after Step 1.</P>
<P>Five classes have been created for you. For the application FirstSDI, they are
as follows:</P>

<UL>
	<LI>CAboutDlg, a dialog class for the About dialog box
	<P>
	<LI>CFirstSDIApp, a CWinApp class for the entire application
	<P>
	<LI>CFirstSDIDoc, a document class
	<P>
	<LI>CFirstSDIView, a view class
	<P>
	<LI>CMainFrame, a frame class
</UL>

<P>Dialog classes are discussed in Chapter 2, &quot;Dialogs and Controls.&quot; Document,
view, and frame classes are discussed in Chapter 4. The header file for CFirstSDIApp
is shown in Listing 1.1. The easiest way for you to see this code is to double-click
on the classname, CFirstDSIApp, in the ClassView pane. This will edit the header
file for the class.</P>
<P>
<H4>Listing 1.1&#160;&#160;FirstSDI.h--Main Header File for the FirstSDI Application</H4>
<PRE>// FirstSDI.h : main header file for the FIRSTSDI application
//
#if !defined(AFX_FIRSTSDI_H__CDF38D8A_8718_11D0_B02C_0080C81A3AA2__INCLUDED_)
#define AFX_FIRSTSDI_H__CDF38D8A_8718_11D0_B02C_0080C81A3AA2__INCLUDED_
#if _MSC_VER &gt;= 1000
#pragma once
#endif // _MSC_VER &gt;= 1000
#ifndef __AFXWIN_H__
     #error include `stdafx.h' before including this file for PCH
#endif
#include &quot;resource.h&quot;       // main symbols
/////////////////////////////////////////////////////////////////////////////
// CFirstSDIApp:
// See FirstSDI.cpp for the implementation of this class
//
class CFirstSDIApp : public CWinApp
{
public:
     CFirstSDIApp();
// Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CFirstSDIApp)
     public:
     virtual BOOL InitInstance();
     //}}AFX_VIRTUAL
// Implementation
     //{{AFX_MSG(CFirstSDIApp)
     afx_msg void OnAppAbout();
          // NOTE - The ClassWizard will add and remove member functions here.
          //    DO NOT EDIT what you see in these blocks of generated code!
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations
// immediately before the previous line.

⌨️ 快捷键说明

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