img snaill

WTL for MFC Programmers(2)

发表于2004/4/7 22:17:00  1860人阅读

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:



  • 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:


  • 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/DDVUI更新功能。
  • 实际上提高了MFC的某些特性,如更多变的分割窗体。
  • MFC静态连接更小的可执行文件。
  • 你可以自己在WTL中定位BUG,而不会影响已存在的项目(相对于在MFC/CRT DLL中定位BUG,会使其他程序中断)
  • 如果你仍然需要MFCATL/WTL可以和MFC混合使用(我曾经产生过一个MFCCFrameWnd,它设置一个包含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.



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 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。最初是用来简化COMActiveX编程的(在ATL开发期间,微软的新产品叫作ActiveX,而现在这个产品叫作.NET)当ATL真正的应用在COM编程以后,他只提供了最基础的GUI类,就像MFCCWndCDialog。幸运的是,这些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版可以工作在VC6VC7上,不过需要为VC7定义一对预处理程序标识。WTL 7版在3.1版基础上进行了提升,在VC7上部需要作任何改动,所以没有任何理由再使用3.1版开发新的程序了。

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

0 0



取 消