原创 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




VS 2010 VC++.net自动代码提示插件(自己现在正在使用)

  • 2013年12月04日 13:43
  • 13.12MB
  • 下载


  • 2012年08月02日 16:34
  • 23.92MB
  • 下载

VC++ .Net 实例学习

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

用VC++.Net 创建纯资源类库, 并在MFC Application中调用

 今天经历和大家分享:步骤:    一:用VC++.Net 创建纯资源类库,并在其中增加一个Icon过程如下:1> Visual Studio >> open new project Visual C...
  • toptiger
  • toptiger
  • 2006-12-15 16:00:00
  • 679


  • 2009年11月06日 09:26
  • 11.99MB
  • 下载


  1.源文件:是类成员函数的实现头文件:是类接口申明资源文件:是程序中用到的图片和对话框等资源2.  stdafx.h和stdafx.cpp文件;是第一次编译时系统按这两个文件内容创建预编译头文件(...
  • yefan2222
  • yefan2222
  • 2007-12-04 09:19:00
  • 791

收集一些 文件操作实例源码

  • 2010年08月06日 15:02
  • 220KB
  • 下载


  • 2009年12月14日 11:05
  • 246KB
  • 下载


  • 2008年11月06日 13:29
  • 161KB
  • 下载

VC++6.0 开发宝典

  • 2008年03月19日 22:05
  • 5.58MB
  • 下载