原创 2004年09月06日 11:20:00

The Learning Curve<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    All the benefits sound great, don’t they? But you’re probably thinking, “You don’t get something for nothing.” Yes, that’s true. To use the application framework effectively, you have to learn it thoroughly, and that takes time. If you had to learn C++, Windows, and the MFC library (without OLE) all at the same time, it would take at least six months before you were really productive. Interestingly, that’s close to the learning time for the Win32 API alone.



    所有伟大而有益的声音,都不是他们?但是你大概在想,”你不可能不劳而获”.是的,那时真的.如果你想有效的使用应用程序框架,你不得不花大量的时间彻底的学习它.如果你以前同时学过C++, Windows和MFC(不包括OLE),它们最少需要你花六个月的时间才能弄出个真实的产品.有趣的是,学习的时间接近与Win32API的时间.


How can that be if the MFC library offers so much more? For one thing, you can avoid many programming details that C-language Win32 programmers are forced to learn. From my own experience, I can say that and object-oriented application framework makes programming for Windows easier to learn --- than is , once you understand object-oriented programming.

    怎么使MFC更加有价值呢? 首先,你能避免许多Win32的C语言程序员不的不面对的细节。从我以往的经验,在windows下写面向对象的程序是非常容易学习的,当然,你曾经学习过面向对象的程序设计.


    The MFC library won’t bring real Windows-based programming to the masses. Programmers of applications for Windows have usually commanded higher salaries than other programmers, and that situation will continue. The MFC library’s learning curve, together with the application framework’s power, should ensure that MFC library programmers will continue to be in strong demand.



    What’s an Application Framework?

    One definition of application framework is “ an integrated collection of object-oriented software components that offers all that’s needed for a generic application.” That isn’t a very useful definition, is it? If you really want to know what an application framework is, you’ll have to read the rest of this book. The application framework example that you’ll look at later in this chapter is a good starting point.




    An Application Framework VS. a Class Library

    One reason that C++ is a popular language is that is can be “extended” with class libraries. Some class libraries are delivered with C++ compilers, others are sold by third-party software firms, and still others are developed in-house. A class library is a set of related C++ classes that can be used in an application. A mathematics class library, for example, might perform common mathematics operations, and a communications class library might support the transfer of data over a serial link. Sometimes you construct objects of the supplied classes, sometimes you derive your own classes—it all depends on the design of the particular class library.




    An application framework is a superset of a class library. An ordinary library is an isolated set of classes designed to be incorporated into any program, but an application framework defines the structure of the program itself. Microsoft didn’t invent the application framework concept. It first appeared in the academic world, and the first commercial version was MacApp for the Apple Macintosh. Since the MFC library 2.0 was introduced, other companies, including Borland, have released similar products.



An Application Framework Example

  Enough generalizations. It’s time to look at some code—not pseudocode but real code that actually complies and runs with MFC library. Guess what? It’s the good old “Hello, world!” application, with a few additions. (If you’ve used version 1.0 of the MFC library, this code will be familiar except for the frame widows base class.) It’s about the minimum amount of code for a working MFC library application for Windows.(Contrast it with an equivalent pure Win32 application such as you would see in a Petzold book!) You don’t have to understand every line now. Don’t bother to type it in and test it, because EX21B on the companion CD is quite similar. Wait for the next chapter, where you’ll start using the “real” application framework.


    一个非常普遍的例子。是时候看一些代码了­—没有伪代码,是真正的代码,是可以编译和运行在MFC库上的。猜是什么? 是一个很古老的“Hello,world!“程序,(如果你用过MFC1。0,那么这个程序是你除那些框架之外最熟悉的了)。他大概是可以运行在MFC框架上代码数量最少的程序了.(跟那些纯WIN32的应用程序相等,例如你将在Petzold的书中看到的).你现在不需要明白每一行代码.你不必担心它的类型和测试它,因为EX21B在随书的CD中有个相同的例子。等到下一章,你将看到真正的应用框架。


Note By convention, MFC library class names begin with the letter C.


    Following is the source code for the header and implementation files for our MYAPP application. The classes CMyApp and CmyFrame are each derived from MFC library base classes. First, here is the MyApp.h header file for the MYAPP application:


注解 按管理,MFC的类名字来自与C




    //application class

    class CMyApp: public CWinApp



        Virtual BOOL InitInstance():



    //frame window class

    class CMyFrame: public CFrameWnd





        //”afx_msg” indicates that the next two functions are part

       // of the MFC library message dispatch system

        afx_msg void OnLButtonDown(UNIT nFlag,Cpoint point);

        afx_msg void OnPaint();




       And here is the MyApp.cpp implementation file for the MYAPP application;



#include <afxwin.h> //MFC library header file declares base classes

#include “myapp.h”


CmyApp theApp; //the one and only CmyApp object


BOOL CmyApp::InitInstance()


    m_pmainwnd =new cmyframe();




    return TRUE;










    Create(NULL,”MYAPP Application”);



void CmyFrame::OnLButtonDown(UNIT nFlags,Cpoint point)


    TRACE(“Entering CmyFrame::OnLButtonDown--%1x,%d,%d/n”,

           (long) nflags, point.x, point.y);



void CmyFrame::OnPaint()


    CpaintDC dc(this);




    Here are some of the program elements:



The WinMain function

 Windows requires your application to have to WinMain function. You don’t see WinMain here because it’s hidden inside the application framework.





The CmyApp class

    An object of class CmyApp represents and application. The program defines a single global CmyApp object, theApp. the CwinApp base class determines most of the theApp object’s behavior.




Application startup

    When the user starts the application, Windows calls the application framework’s built-in WinMain function, and WinMain looks for your globally constructed application object of a class derived from CwinApp. Don’t forget that in a C++ program global objects are constructed before the main program is executed.





The CmyApp::InitInstance member function

    When the WinMain function finds the application object, it calls the virtual InitInstance member function, which makes the calls needed to construct and display the application’s main frame window. You must override InitInstance in your derived application class because the CwinApp base class doesn’t know what kind of main frame window you want.





The CwinApp::Run member function

    The Run function is hidden in the base class, but it dispatches the application’s messages to its windows, thus keeping the application running. WinMain calls Run after it calls InitInstance




VC++ .Net 实例学习

VC++.NET中添加由C#编译的DLL引用的方法 关于VC.NET的资料网络上...
  • bcbobo21cn
  • bcbobo21cn
  • 2017年06月18日 16:55
  • 780


01-IO流(输入流&输出流)输入流和输出流相对于内存设备而言.将外设中的数据读取到内存中:输入 将内存的数写入到外设中:输出。02-IO流(字节流&字符流)字符流的由来:其实就是:字节流读取文字字...
  • qq_24653023
  • qq_24653023
  • 2016年08月25日 18:03
  • 1013


  • chenghuaying
  • chenghuaying
  • 2014年03月31日 16:47
  • 4557


为知笔记 Linux 版 2015-12-03 产品更新 提示:软件的名称由wiznote修改为WizNote,在终端命令行下需要使用WizNote来打开程序。 更新日志: 2.3.2 版本(201...
  • Lina_ACM
  • Lina_ACM
  • 2016年08月03日 10:41
  • 803


转自: 在电路中反向并联在继电器或电感线圈的两端,当电感...
  • yc550370460
  • yc550370460
  • 2013年01月21日 10:20
  • 1791


之前在coursera上看了Andrew Ng的机器学习课程,那个课程比较简明,适合对机器学习有一个整体的印象,但是很多细节的内容和推导都忽略了。现在想要了解机器学习更多,所以开始看Andrew Ng...
  • zhonglj0314
  • zhonglj0314
  • 2017年02月20日 09:57
  • 531

《Java JDK8学习笔记》读书笔记(4)

第4章 认识对象 学习目标  区分基本类型与对象类型  了解对象与引用的关系  从打包器认识对象  以对象观点看待数组  认识字符串的特性...
  • mouyong
  • mouyong
  • 2016年04月18日 20:10
  • 4421

Angularjs 学习笔记(一)基础

1.简介: Angular JS (Angular.JS) 是一组用来开发Web页面的框架、模板以及数据绑定和丰富UI组件。它支持整个开发进程,提供web应用的架构,无需进行手工DOM操作。 Ang...
  • qq_25178609
  • qq_25178609
  • 2016年10月02日 16:13
  • 478


在项目中使用myBatis 导入jar包 在src下创建配置文件
  • u010837612
  • u010837612
  • 2015年05月12日 11:06
  • 894

Spring MVC 学习笔记(一)

(* 笔记内容均来自 尚硅谷 佟刚老师的视频,例子是在学习中照着敲的) 内容概要 • 1.SpringMVC概述 • 2.SpringMVC的HelloWorld • 3.使用@RequestMapp...
  • u011870547
  • u011870547
  • 2016年01月07日 14:50
  • 1704