VC++.NET学习笔记(续)

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

    MFC是真正的开发Windows程序的工具,开发WINDOWS程序的程序员比那些在命令行模式下的程序员工资要高,并且地位会更高.学习MFC,在加上应用程序框架的力量将保证使用MFC的程序员提供更强壮的需求.

 

    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.

    应用程序框架与类库的比较

    C++能成为通用语言的理由是它能被无限扩展.C++的编译器包含了一些类库,有些第三方厂家在出售,而有些则在家里开发。一个类库在C++类中设置一下关系就可以在你的应用程序中使用。例如,一个数据类库,可以完成通用的数据运算,一个通信类库可以支持多个连接进行数据传输。有时你需要通过支持类来构造对象。有时你需要来自你自己的类—这一切是依靠独特的类库设计。

 

    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.

    应用程序框架是类库的扩展。在任何一个程序中,类是有许多独立的库组合而成的,但是在应用程序框架定义的结构中是程序自身。微软不可能发明应用程序框架的概念。最先出现在学术界,第一个商业版是APPLE的MAC系统的中的MacApp,后来有了MFC2。0,其他公司,如Borland,也发布了类似的产品.

   

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

   

    从头开始执行我们的MYAPP程序的源代码文件.CmyApp和CmyFrame是来者与MFC库基类的.首先,这儿是MYAPP程序的头文件MyApp.h:

   

    //application class

    class CMyApp: public CWinApp

    {

    Public:

        Virtual BOOL InitInstance():

    };

   

    //frame window class

    class CMyFrame: public CFrameWnd

    {

    public:

        CMyFrame();

    Protected:

        //”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();

        DECLARE_MESSAGE_MAP()

    };

   

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

 

    和这里是MYAPP程序MyApp.cpp的可执行文件

#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();

    m_pmainwnd->showwindow9m_ncmdshow);

   

    m_pmainwnd->updatewindow();

    return TRUE;

}

 

BEGIN_MESSAGE_MAP(CmyFrame,CframeWnd)

    ON_WM_LBUTTONDOWN()

    ON_WM_PAINT()

END_MESSAGE_MAP

 

CmyFrame::CmyFrame()

{

    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);

    dc.TextOut(0,0,”Hello,world!”);

}

 

    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.

   

WinMain函数

    Windwos通过WinMain函数来请求你的应用程序,你看不到WinMain函数的,因为它被隐藏在应用程序框架中.

   

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.

CmyApp类

    CmyApp类对象是应用程序的声明.CmyApp对象在程序中定义了一个全局对象theApp.CwinApp基类是定义theApp对象的行为的.

 

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.

   

应用程序启动

    当用户启动应用程序,Windows调用应用程序框架里绑定的WinMain函数,这个来自CWinApp函数会寻找你程序里全局构造的应用程序对象.不要忘了C++程序构造的对象是在你主程序之前执行的.

   

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.

 

CmyApp::InitInstance成员函数

    当WinMain函数找到应用程序对象,它调用虚函数InitInstance,接着构造和显示应用程序主窗口.你必须在你的应用程序中重载InitInstance,因为CwinApp基类不知道你想要什么样的主窗口.

   

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

CwinApp::Run成员函数

    Run函数是隐藏在基类的,但是会发送程序的信息给Windwos,因此保持着应用程序的运行.WinMain是在调用了InitInstance之后调用Run的.

   

VC++ .Net 实例学习

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

毕向东Java视频学习笔记【day21-IO流<1>】

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

Linux学习笔记之——起始篇

摘要:学习笔记目录、方便以后回顾、没有什么捷径可走、不断的记录、总结、练习、coding、coding。...
  • 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

继电器与续流二极管

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

斯坦福机器学习网易公开课笔记1

之前在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学习笔记(1)——快速入门

在项目中使用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
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:VC++.NET学习笔记(续)
举报原因:
原因补充:

(最多只允许输入30个字)