WTL for MFC Programmers(2)

类别:VC语言 点击:0 评论:0 推荐:
Introduction to the Series

WTL rocks. It does. It has a lot of the power of MFC's GUI classes, yet produces substantially smaller executables. If you're like me, and learned GUI programming with MFC, you've become quite comfortable with all the control wrappers MFC provides, as well as with the flexible message handling built into MFC. If you're also like me and don't relish the idea of several hundred K of MFC framework getting added to your programs, WTL is for you. However, there are a few barriers we have to overcome:

 

    WTL有类似MFC那样的GUI类的功能,也能够产生足够小的可执行文件。如果你像我使用MFC来进行GUI编程,你已经非常习惯的使用MFC封装的控件,灵活的使用MFC提供的消息方式;如果你像我,不希望MFC数百K的框架程序随你的程序发布,那么WTL将适合你。然而,我们还须克服一些困难:

ATL-style templates look weird at first. No ClassWizard support, so writing message maps involves some manual labor. No documentation in MSDN, you need to find it somewhere else, or even look at the WTL source. No reference books you can buy and keep on your shelf. It has that "not officially supported by Microsoft" stigma ATL/WTL windowing is sufficiently different from MFC windowing that not all your knowledge transfers over. 首先,ATL风格的模板看起来是怪异的。 没有类型向导的支持,所有的事件映射都需要手写。 没有像MSDN那样的文档,经常需要参照WTL的源码。 没有能够购买的参考书。 微软不提供官方的支持。 ATL/WTL的窗体和MFC有着巨大的不同。

On the other hand, the benefits of WTL are:

另一方面,WTL的优点是:

No complex doc/view framework to learn or work around. Has some essential UI features from MFC, like DDX/DDV and "update command UI" functionality. Actually improves on some MFC features (e.g., more flexible splitter windows) Much smaller executables compared to a statically-linked MFC app. You can apply bug fixes to WTL yourself and not affect existing apps (compare this with replacing the MFC/CRT DLLs to fix a bug in one app, and having other apps break) If you still need MFC, MFC and ATL/WTL windows can co-exist peacefully (for a prototype at work, I ended up creating an MFC CFrameWnd that contained a WTL CSplitterWindow, which contained MFC CDialogs -- that wasn't me showing off, it was modifying existing MFC code but using the nicer WTL splitter). 没有复杂的文档/视图框架需要学习并在其上工作。 提供MFC UI的本质特性,如DDX/DDV和UI更新功能。 实际上提高了MFC的某些特性,如更多变的分割窗体。 比MFC静态连接更小的可执行文件。 你可以自己在WTL中定位BUG,而不会影响已存在的项目(相对于在MFC/CRT DLL中定位BUG,会使其他程序中断) 如果你仍然需要MFC,ATL/WTL可以和MFC混合使用(我曾经产生过一个MFC的CFrameWnd,它设置一个包含MFC CDialog类的WTL CSplitterWindow类,通过这样做,我使用更漂亮的WTL分割器代替了MFC中已有的代码

In this series, I will first introduce the ATL windowing classes. WTL is, after all, a set of add-on classes to ATL, so a good understanding of ATL windowing is essential. Once I've covered that, I'll introduce WTL features and show how they make GUI programming a lot easier.

 

    在这个系列,我将首先介绍ATL的窗体类。由于WTL实际是一套ATL的扩展类,所以充分的了解ATL窗体类很重要。在此之后,我将介绍WTL的特性和如何使用他们来简化GUI编程。

Introduction to Part I

WTL rocks. But before we get to why, we need to cover ATL first. WTL is a set of add-on classes to ATL, and if you've been strictly an MFC programmer in the past, you may never have encountered the ATL GUI classes. So please bear with me if I don't get to WTL right off the bat; the detour into ATL is necessary.

 

    在我们了解WTL之前,我们需要先了解ATL。由于WTL是一套ATL的扩展类,而且如果你以前是一个完全的MFC程序员的话,你可能从没有接触过ATL GUI类。所以请原谅我没有直接讲述WTL,因为绕道ATL很重要。

 

In this first part, I will give a little background on ATL, cover some essential points you need to know before writing ATL code, quickly explain those funky ATL templates, and cover the basic ATL windowing classes.

在第一部分,我将给出一点ATL的知识,讲述一些在写ATL代码前你需要知道的基础要点,快速的说明那些让人心惊胆战的ATL模板,并揭示基本的ATL窗体类。

ATL Background ATL and WTL history

The Active Template Library... kind of an odd name, isn't it? Old-timers might remember that it was originally the ActiveX Template Library, which is a more accurate name, since ATL's goal is to make writing COM objects and ActiveX controls easier. (ATL was also developed during the time that Microsoft was naming new products ActiveX-something, just as new products nowadays are called something.NET.) Since ATL is really about writing COM objects, it only has the most basic of GUI classes, the equivalent of MFC's CWnd and CDialog. Fortunately, the GUI classes are flexible enough to allow for something like WTL to be built on top of them.

 

     Active Template Library(活动模板库)似乎不像一个固定的名字,它的更确切的名字应该是ActiveX Templeate Library。最初是用来简化COM和ActiveX编程的(在ATL开发期间,微软的新产品叫作ActiveX,而现在这个产品叫作.NET)当ATL真正的应用在COM编程以后,他只提供了最基础的GUI类,就像MFC的CWnd和CDialog。幸运的是,这些GUI的灵活性已经足够在其上建立像WTL这样的类库了。

 

WTL is currently in its second revision. The first was version 3.1, and the second is version 7. (The version numbers were chosen to match the ATL version numbers, that's why they're not 1 and 2.) Version 3.1 works with VC 6 and VC 7, although you need to define a couple of preprocessor symbols for VC 7. WTL version 7 is a drop-in replacement for version 3.1, and works without modification on VC 7, so there really is no reason to use 3.1 for new development.

   

    WTL的当前版本是他的第2个版本。第一个版本是3.1,第2个版本是7。(这个版本是跟随ATL的版本号定义的,并不是连续的)3.1版可以工作在VC6和VC7上,不过需要为VC7定义一对预处理程序标识。WTL 7版在3.1版基础上进行了提升,在VC7上部需要作任何改动,所以没有任何理由再使用3.1版开发新的程序了。

(现在WTL的最新版为7.1 --- 蜗牛手记)

本文地址:http://com.8s8s.com/it/it1042.htm