The Joys of WTL
By Simon Steele
Wednesday, April 17, 2002
last updated: 2nd May 2003
What's this WTL thing then?
Warning: if you're not a C++ programmer, then you don't want to bother reading this - there's nothing for you here!
The Windows Template Library (WTL) is MFC on template-based steroids - after a successful stretch on the slimfast plan. WTL provides the user-interface frameworks that we need to write proper GUI applications without resorting to the bloated MFC or complicated pure Win32 API programming. A number of the "must-have" classes from MFC are also available as WTL utility classes too, welcome back your old friends CPoint, CSize, CRect and most importantly CString! WTL produces small executables that do not require the MFC run time libraries - in fact if you stay clear of the Visual C++ runtime functions (strcpy and friends) you can dispense with msvcrt.dll as well - leading to really small programs, which run fast too.
WTL comes with visual studio application wizards for both Visual C++ 6 and 7 (.NET) which will create WTL projects in a variety of different configurations - MDI, SDI, Multiple-Thread SDI and even Dialog based. There is also various other bits of support given throughout dev studio, although notably class wizard support is lacking. The wizard will create applications that include toolbars (based on ReBars, there's no built-in docking framework, see below) and menus with all of the images working out-of-the-box (tm).
WTL windows support message maps similar to those you're used to from MFC (although not quite as great, because the wizard support is lacking) and provides light-weight wrappers for all windows common controls - including up-to-date support for the Windows XP controls and styles.
So why should I use it then?
Well, if the above reasons aren't enough for you, then you maybe shouldn't be using it - there is no real documentation yet, although some projects are under way to resolve that (see below), and WTL is officially unsupported (although see here and here). However, if you want to develop with a proper modern C++ framework then you shouldn't take my word for it, you should try WTL yourself (see below for links).
Some people are instantly disuaded by the lack of features such as docking windows and toolbars - yes this would be a nice feature but there are already a couple of good implementations of docking-style functionality (although not for toolbars, and again links below). A lot of good programmers are getting into WTL programming and there must be reasons for this - I find myself spending more time fighting against MFC more than I gain from its benefits - with WTL this isn't the case.
There are problems you'll have to solve for yourself that MFC makes easy. For example, in MFC if you want to get a window from its HWND, you simply call CWnd::FromHandle(myHwnd) but this functionality doesn't exist for free in WTL - this means no irritating Handle Maps to trip over (Yay!) but that you'll have to find your own way to implement this functionality should you need it (new article coming soon!). MFCs Document/View mentality is also notably missing - I think "Great!", but you might miss it. If so, there are several articles around which explain how to add this functionality to a project should you want it. You may miss the compound document support as well, but perhaps the other benefits of using WTL will outweigh these minor downsides.
OK, OK, enough of your babble. Where do I get it?
WTL 7.0 (direct download link from MSDN, could move)
On MSDN: Go to Developer Downloads, Visual Studio, Visual C++, Windows Template Library.
WTL 7.0 (Microsoft Downloads)
And where do I learn about it?
Start with the excellent tutorial series by Michael Dunn on Code Project:
WTL Documentation Projects:
With the above two sites, Doxygen has been used to extract the code structure from the WTL source code and the documentation project aims to fill in documentation for the files, classes and members present. Bjarke's site provides a downloadable HTML Help version of the documentation, and the Doxygen work is available from the Gnomedia site (with lots of Bjarke's annotations pulled in). You see what I'm trying to do here is not give too much credit to either for this brilliant resource. There's not a huge amount of documentation yet, but the call for help is out.
WTL Quick Ref Document by Bryan Ressler
This is a really useful resource, a one-page (albeit a big one) cheat sheet for WTL 3.1 - most of the classes have not changed for the new 7.0 release so this is still a great resource.
This started out as a good effort to document WTL but is in online HTML format which makes it a little annoying to use (especially for those with modem dial-up connections). In addition, there needs to be a lot more content before it becomes more useful. A good effort all the same.
WTL Articles and Information Sites:
(plus all those links I referred to in the text)
Bjarke Viksoe's WTL code
This site has loads of really useful WTL classes, it's also the first place to look for some Docking Windows implementation code.
CodeProject has a whole section dedicated to WTL programming with some fantastic articles and classes. There is a really good Docking framework here, and also a "Snapping" framework which is similar but provides VS.NET style pop-out, pinnable, snapping windows.
The Yahoo WTL Group
This group gets input from Nenad Stefanovic who is one of the WTL developers at Microsoft and also has a number of other well informed members. A good place to look for WTL information and help.
Particularly good WTL code libraries:
Custom Tab Controls, Tabbed Frame and Tabbed MDI
A tab framework for WTL applications - this provides an excellent tab control implementation and loads of code to help you get a nice tabbed UI - thanks to Daniel Bowen.
WTL Docking windows
An excellent docking windows framework for WTL from Sergey Klimov.
So how can I get involved in a WTL project?
Programmers Notepad 2 is being developed using WTL - if you want to get some WTL experience or just have a look then how about joining the effort.
This page will be updated as and when I find more useful WTL information or I get told that I've got something wrong (no, it does happen, really). I hope I've given someone a useful introduction to WTL.
Simon.Back to top...