WTL for MFC Programmers(2)
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:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
- 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.
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/DDV和UI更新功能。
- 你可以自己在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.
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.
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.
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的最新版为7.1 --- 蜗牛手记）