WTL for MFC Programmers(2)

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

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/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.

 

    在这个系列,我将首先介绍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。最初是用来简化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 --- 蜗牛手记)

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WTL 具有两面性,确实是这样的。它没有MFC的界面(GUI)类库那样功能强大,但是能够生成很小的可执行文件。如果你象我一样使用MFC进行界面编程,你会觉得MFC提供的界面控件封装使用起来非常舒服,更不用说MFC内置的消息处理机制。当然,如果你也象我一样不希望自己的程序仅仅因为使用了MFC的框架就增加几百K的大小的话,WTL就是你的选择。当然,我们还要克服一些障碍: ATL样式的模板类初看起来有点怪异 没有类向导的支持,所以要手工处理所有的消息映射。 MSDN没有正式的文档支持,你需要到处去收集有关的文档,甚至是查看WTL的源代码。 买不到参考书籍 没有微软的官方支持 ATL/WTL的窗口与MFC的窗口有很大的不同,你所了解的有关MFC的知识并不全部适用与WTL。 从另一方面讲,WTL也有它自身的优势: 不需要学习或掌握复杂的文档/视图框架。 具有MFC的基本的界面特色,比如DDX/DDV和命令状态的自动更新功能(译者加:比如菜单的Check标记和Enable标记)。 增强了一些MFC的特性(比如更加易用的分隔窗口)。 可生成比静态链接的MFC程序更小的可执行文件(译者加:WTL的所有源代码都是静态链接到你的程序中的)。 你可以修正自己使用的WTL中的错误(BUG)而不会影响其他的应用程序(相比之下,如果你修正了有BUG的MFC/CRT动态库就可能会引起其它应用程序的崩溃。 如果你仍然需要使用MFCMFC的窗口和ATL/WTL的窗口可以“和平共处”。(例如我工作中的一个原型就使用了了MFC的CFrameWnd,并在其内包含了WTL的CSplitterWindow,在CSplitterWindow中又使用了MFC的CDialogs -- 我并不是为了炫耀什么,只是修改了MFC的代码使之能够使用WTL的分割窗口,它比MFC的分割窗口好的多)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值