原创 2004年08月28日 10:58:00

第二章<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    The Microsoft Foundation Class Library Application Framework



    This chapter introduces the Microsoft Foundation Class (MFC) library 7.0 Application Framework and explains its benefits. It includes a stripped-down but fully operational MFC library program for Microsoft Windows that should help you understand what application framework programming is all about. I’m keeping theory to a minimum here, but I’ve included sections on message mapping and on documents and views to help you understand the examples in later chapters.




Why Use The Application Framework?



    If you’re going to develop applications for Windows, you’ve got to choose a development environment. Assuming that you’ve already rejected non-C options such as Microsoft Visual Basic and Borland Delphi, here are some of your remaining options:

    Program in C with the Win32 API.

Writ your own C++ Windows class library that uses Win32.

    Use the MFC library application framework

    Use another Windows-based application framework. (Most of Them

Are defunct, however-such as Borland’s Object Windows Library [OWL].)








NOTE  We’ll cover .NET Windows Forms in Part VI of this book.


解释:在我们书的第六部分包括.NET的Windows 的窗体.



    If you’re starting from scratch, any option will involve a big learning curve. If you’re already a Win32 programmer, you’ll still have a learning curve with the MFC library. Since its release, the MFC library has become the dominant Windows class library. But even if you’re familiar with it it’s still a good idea to step through the features of this programming choice.



The MFC library is the low-level C++ interface to the Windows API

C++ has been a standard for many developers for a number of years. It’s turned into a mature, well-understood framework with great third-party support. If you need the highest-performance applications, your applications must live as closely to the Windows API as possible. C++ and MFC are as close as you can get without writing WndProc methods by hand.

MFC库是基于低级C++语言的Windows API的接口

    C++是许多开发者支持许多年的标准.它是成熟的良好的框架,得到许多第三方的支持.如果你需要高效的应用程序,你的应用程序必须接近Windows API的运行的可能.C++和MFC已不在支持你去写WNDPROC这样的方法.


Application framework applications use a standard structure

    Any programmer starting on a large project develops some kind of structure for the code. The problem is that each programmer’s structure is different, and it’s difficult for a new team member to learn the structure and conform to it. The MFC library application framework includes its own application structure—one that’s been proven in many software environments and in many projects. If you write a program for Windows that uses the MFC library, you can safely retire to a Caribbean island, knowing that your minions can easily maintain and enhance your code back home.




    Don’t think that the MFC library’s structure makes your programs inflexible. With the MFC library, your program can call Win32 functions at any time, so you can take maximum advantage of Windows.



Application framework applications are small and fast

    Back in the 16-bit days, you could build a self-contained Windows EXE file that was less than 20 KB in size. Today, Windows-based programs are larger. One reason is that 32-bit code is fatter. Even with the large memory model, a Win16 program uses 16-bit addresses for stack variables and many globals. Win32 programs use 32-bit addresses for everything and often use 32-bit integers because they’re more efficient than 16-bit integers. In addition, the C++ exception-handling code consumes a lot of memory.




    That old 20KB program didn’t have a docking toolbar, splitter windows, print preview capabilities, or control container support—features that users now expect. MFC programs are bigger because they do more and look better.    Fortunately, it’s now easy to build applications that dynamically link to the MFC code(and to C run-time code), so the size goes back down again—from 192KB to about 20KB! Of course, you’ll need some big support DLLs in the background , but those are a fact of life these days.



    As far as speed is concerned, you’re working with machine code produced by an optimizing compiler. Execution is fast, but you might notice a startup delay as the support DLLs are loaded.



The Visual C++.NET tools reduce coding drudgery

    The Visual C++.NET resource editors, the MFC Application Wizard, and the code wizards available from Class View significantly reduce the time needed to write code that’s specific to your application. For example, the resource editor creates a header file that contains assigned values for #define constants. The MFC Application Wizard generates skeleton code for your entire application, and you can use the Properties window to add message handlers and map messages to them.

Visual C++的自带工具可以减少编码的难度

    Visual C++自带的资源编辑器,应用程序向导,类代码生成器向导可以大幅度的减少我们编码的时间.例如:用资源编辑器建立头文件中用#define定义的常数.MFC的应用程序向导可以为你的程序建立完整的框架代码,并且你能用属性窗口中增加消息头跟消息映射.


The MFC library application framework is feature rich

    The MFC library 1.0 classes, introduced with C/C++7.0, included the following features:

    A C++ interface to the Windows API

    General-purpose (non-Windows-specific) classes, including:

        Collection classes for lists, arrays, and maps

       A useful and efficient string class

       Time, time span, and date classes

       File access classes for operating system independence

Support for systematic object storage and retrieval to and from disk

    A “common root object” class hierarchy

    Streamlined Multiple Document Interface(MDI) application support

    Some support for OLE1.0



        Windows API是C++语言封装的接口

       通用性(非Windows 类)¸包括:










The MFC library 2.0 classes (in Visual C++ 1.0) picked up where the version 1.0 classes left off by supporting many user interface features that are found in current Windows-based application, plus they introduced the application framework architecture. Here’s a summary of the important new features:

    Full support for File Open, Save and Save as commands and the most recently used file list

    Print preview and printer support

    Support for scrolling windows and splitter windows

    Support for toolbars and status bars

    Access to Visual Basic controls

    Support for context-sensitive help

    Support for automatic processing of data entered in a dialog box

    An improved interface to OLE 1.0

DLL support


MFC2.0类库(在Visual C++ 1.0)在原来1.0的基础上被精简了,当前程序发现在没有它支持的许多用户接口的特色上,正引入了应用程序框架体系.这里大概介绍以下几个重要的特色:








    改进了OLE 1.0的接口



The MFC library 2.5 classes (in Visual C++1.5) contributed the following:

    Open Database Connectivity (ODBC) support that allows you application to access and update data stored in many popular databases such as Microsoft Access, Microsoft FoxPro, and Microsoft SQL Server

An interface to OLE 2.01,with support for in-place editing, linking, Drag and drop, and OLE Automation

    MFC2.5版(在Visual C++1.5中)有下列贡献:


例如Microsoft Access, Microsoft FoxPro,和Microsoft SQL Server.



    Visual C++2.0 was the first 32-bit version of the product. It included support for Microsoft Windows NT version 3.5. It also contained the MFC library 3.0, which had the following new features:

    Tab dialog box (property sheet) support (which was also added to Visual C++ 1.51, included on the same CD)

    Docking control bars that were implemented within MFC

    Support for thin-frame windows

    A separate Control Development Kit (CDK) for building 16-bit and 32-bit OLE controls, although no OLE control container support was provided

    Visual C++2.0是第一个32位版本的产品.它支持Windows NT3.5版.它包含MFC3.0的库.以下是它的几个新特征:

    Tab对话框(属性页)支持(在Visual C++1.51中也增加了,在同一个CD里)





    A subscription release, Visual C++2.1 with the MFC library 3.1, added the following:

    Support for the new Windows 95 (beta) common controls

    A new ODBC Level 2 driver integrated with the Access Jet database engine

    Winsock classes for TCP/IP data communication

    使用MFC3.1版的Visual C++2.1的发布,增加了下列特性:

    支持新的Windows 95(beta)通用控件




    Microsoft decided to skip Visual C++3.0 and proceeded directly to 4.0 in order to synchronize the product version with the MFC library. The MFC library 4.0 contains these additional features:

    New OLE-based Data Access Object (DAO) classes for use with the Jet engine

    Use of the Windows 95 docking control bars instead of the MFC control bars

    Full support for the common controls in the released version of Windows 95, with new tree view and rich-edit view classes

    New classes for thread synchronization

    OLE control container support

    Microsoft决定跳过Visual C++3.0并继续开发MFC4.0的类库.MFC4.0增加了以下特征:


    使用Windows 95的停靠拦控件代替了MFC的控件

    完全支持Windows 95的公共控件,及新的树控件跟RichEdit控件.




    Visual C++4.2 was and important subscription release that included the MFC 4.2. The following new features were included:

    WinInet classes

    ActiveX Documents Server classes

    ActiveX synchronous and asynchronous moniker classes

    Enhanced MFC ActiveX Control classes, with features such as windowless activation, optimized drawing code, and so forth

    Improved MFC ODBC support, including recordset bulk fetches and data transfer without binding.

    Visual C++ 4.2是个重要的版本,它包括MFC4.2.它包括以下新的特征:

    WinInt 类



    增强的MFC ActiveX类,它包括了灵活的无窗,最优化的绘图代码等等.

    改良了MFC ODBC的支持,这包括取记录集的大小和无绑定的数据传输.


    Visual C++ 5.0 included the MFC library 4.21, which fixed some 4.2 bugs.    Visual C++5.0 introduced some worthwhile features of its own as well:

    A redesigned IDE, Microsoft Developer Studio 97, which included and HTML-based online help system and integration with other languages, including Java

    The Active Template Library (ATL) for efficient ActiveX control construction for Internet

    C++ language support for COM(Component Object Model) client programs with the new #import statement for type libraries, as described in Chapter25.

    Visual C++5.0包括MFC4.21,它修复了一些4.2的错误.Visual C++5.0包括一些很突出的特点:

    从新设计了IDE, Microsoft Developer Studio 97,它包含了基于HTML在线帮助系统并集成了其他语言,包括Java



    Visual C++ 6.0 includes the MFC library 6.0 (Notice that the versions are synchronized again.) Many of the features in the MFC library 6.0 enabled developers to support the modern platform at the time, the Microsoft Active Platform, including the following:

    MFC classes that encapsulate the new Windows common controls introduced as part of Microsoft Internet Explorer 4.0

    Support for Dynamic HTML(DHTML),which allows MFC programmers to create applications that can dynamically manipulate and generate HTML pages

    Active Document Containment, which allows MFC-based applications to contain Active Documents

    OLE DB Consumers and Providers Template support and ActiveX Data Objects (ADO) data binding, which help database developers who use the MFC library or ATL

    Visual C++6.0包括MFC6.0(又是同步发部的版本),MFC6.0有许多新的特征帮助开发人员支持当时最新的平台,Microsoft活动平台,包括下列特色:

    MFC封装了新的Windows通用控件同时引入了Microsoft IE4.0



    OLE 客户和提供者摸板支持   和ADO数据绑定,可以帮助那些数据库开发者使用MFC和ATL


    The latest edition of Visual C++, Visual C++.NET ,includes the MFC library 7.0. Many of the features in the MFC library 7.0 support Internet programming (and the new Microsoft .NET platform) and also improve the Windows development environment. The new features include the following:

    Enhanced Support for HTML help within MFC applications

    Support for windowless controls

    DHTML dialog boxes and editing components

    HTTP argument management classes

    Windows 2000 Print dialog box

    Stricter message-handler type checking

    Date support beyond the year 2038


最近的Visual C++版本,Visual C++.NET包含MFC7.0.拥有许多特色的MFC7.0支持Internet编程(在新的Microsoft .NET平台)并同样改进了Windows开发环境.新的特色如下:





    Windows 2000的打印对话框




第一行代码学习笔记-第二章 探究活动-1.活动的基本用法

1.创建一个activity 创建一个类,包名就是创建项目时候的包名,继承Activity,重新onCreate方法 在res的layout中创建一个Android XML File,root e...
  • yeehei
  • yeehei
  • 2015-09-12 22:47:05
  • 386


一个进程就是一个正在执行程序的实例,包括程序计数器,寄存器和变量的当前值.从概念上说,每个进程拥有它自己的虚拟CPU.实际上真正的CPU在个进程之间来回切换。如果一个程序运行了两遍,则算作两个进程。 ...
  • liuyongli1992
  • liuyongli1992
  • 2016-08-30 14:58:40
  • 260

《深入理解计算机系统》- 学习笔记 - 第二章

第一章  信息的表示和处理 1. 二进制与十六进制: 1. 十六进制数字:0 – F,例子:173A4C 2. 二进制数字:0 – 1,例子:0001 0111 0011 1010 0100 1...
  • u010173489
  • u010173489
  • 2014-01-23 19:29:08
  • 784


  • bruce_6
  • bruce_6
  • 2016-01-06 21:37:05
  • 1388


前言 什么是集体智慧? 答:为了创造新的想法,而将一群人的行为、偏好或思想组合在一起。 第二章:提供推荐 例子:影片推荐 一、名词:协作型过滤算法(collabora...
  • xuyang508
  • xuyang508
  • 2016-12-28 22:50:26
  • 271


  • weixin_38775978
  • weixin_38775978
  • 2017-10-11 13:37:44
  • 38


第一章 1、数据库概念 数据库是一组相关记录的自描述集合。数据库是“自描述”的,是因为它包含了其内容的描述性信息(称为元数据)。数据库是组织、存储、管理、加工数据的仓库。 关系数据库是一组相关表的自描...
  • Mary19920410
  • Mary19920410
  • 2017-03-13 15:19:45
  • 311

PRML 学习笔记(2)

  • RZ_diversity
  • RZ_diversity
  • 2016-03-29 21:12:02
  • 874

<机器学习>(周志华)读书笔记 -- 第二章 模型评估与选择

2.1  经验误差与过拟合 通常,我们使用"错误率"来表示分类中错误的样本占总样本的比例.如果m个样本中有a个错误样本则错误率E=a/m ,对应的,1-a/m称为精度,即"精度"=1-"错误率".更一...
  • geng333abc
  • geng333abc
  • 2017-02-13 15:55:27
  • 972


STL标准模板库作为C++标准库的一部分,其组件包括:容器、算法、迭代器、仿函数、配接器、配置器。          今天来说说容器,容器主要可以分为两种:序列式容器(元素是可序的,但并非有序)、关...
  • Walker19900515
  • Walker19900515
  • 2015-07-29 21:27:41
  • 475