June 23, 2018
Hot Topics:

Windows Mobile Development Made Easier with WTL

  • April 2, 2007
  • By Alex Gusev
  • Send Email »
  • More Articles »

What Is WTL?

The Windows Template Library (WTL), available either from the Microsoft web site or from Source Forge and now in version 8.0, is just what its name states: it is a collection of templates that extends ATL to give you, a developer, all you need to build a better and more complex GUI. This includes frames and dialogs, various controls, GDI objects, and so forth. It is still not a framework, so you're free to use those classes as you want for different use-cases. The last, but not the least, feature is that WTL is supported on both Windows Mobile and Smartphone SDKs, where with the latter you don't have an MFC library. As a result, you have small and efficient code, which is pretty close to a pure Win32 program.

One more useful source of documentation is located here. It is an unofficial site, but it does provide CHM help file for WTL 7.5, which is a very good backend for those who need to study WTL.

Version 7.1 WTL contains Application Wizards for eVC 3.0 and 4.0 as well as for VS 2003. Version 7.5 comes with wizards for MS VS 2005 for desktop and mobile. The latest release is WTL 8.0; it contains minor changes to improve compatibility with VS2005 IDE. Although, even in WTL's documentation Windows Mobile 5.0 SDK isn't listed, you can compile and run apps with Windows Mobile 5.0 SDK after doing the necessarily additions to the standard 'include' folders search path in the IDE.

As the library's documentation says, WTL was not intended for porting between different platforms but rather to allow developers to use the same library everywhere. That may be a real key feature in many aspects, such as common knowledge and re-use of existing code. You might be able to minimize or at least significantly reduce the amount of time needed to get a take-off start in the mobile environment.

Having said all this, you can turn to a quick review of what WTL offers you as a developer.

Building a Simple Application

Once you have installed a wizard, you can use it to create several types of projects similar to MFC ones. The whole process includes just a few steps, depending on which IDE you are using (eVC or Visual Studio 200X); so, in the case of VS2005, first you select a wizard:

Click here for a larger image.

Then, after selecting the required platforms, you can choose a project type suitable for your needs,

Click here for a larger image.

and finally decide what kind of view you want to use in your project for SDI and Multi-threaded SDI architectures:

Click here for a larger image.

There are minor differences between eVC 4.0 and VS2005—for example, in supported view types—but mainly they are the same.

WTL comes with several sample projects, so you can explore them to get more details on how this all is built. Some of them will require minor adjustments to get compiled under Windows Mobile, but that's even for your own benefit because it gives you a good opportunity to learn it quicker. Here I'd like to put Dialog-based application's _tMain function to illustrate how close to a bare Win32 app it is:

int WINAPI _tWinMain(HINSTANCE hInstance,
                     HINSTANCE /*hPrevInstance*/,
                     LPTSTR lpstrCmdLine, int nCmdShow)
   HRESULT hRes = CMainDlg::ActivatePreviousInstance(hInstance, 

   if(FAILED(hRes) || S_FALSE == hRes)
      return hRes;

   hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);


   hRes = _Module.Init(NULL, hInstance);

   int nRet = CMainDlg::AppRun(lpstrCmdLine, nCmdShow);


   return nRet;

As you can see from the SPControls sample, you need minimal effort to get functionality:

You can find the whole list of implemented classes either in readme.htm or the documentation noted above. I would recommend that you also to have a look into the WTL headers to discover which classes are unsupported on Windows Mobile platforms. Also, note that atlwince.h declares about a couple dozen WinCE specific classes, which are really great ones: CHtmlCtrlT, CStdSimpleDialogResizeImpl, or CVoiceRecorderCtrlT are just a small part of them.

Message Maps & Co.

ATL already has things similar to MFC, such as macros for message map, message handlers, command handlers, and many more. WTL doesn't add anything new here. But, the WTL wizard gives you a clue about how to declare different types of handlers:


// Handler prototypes (uncomment arguments if needed):
//   LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/,
//                          LPARAM /*lParam*/, BOOL& /*bHandled*/)
//   LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/,
//                          HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//   LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/,
//                         BOOL& /*bHandled*/)

LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/,
                     LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/,
                   HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
             BOOL& /*bHandled*/);
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
                 BOOL& /*bHandled*/);
LRESULT OnShowText(WORD /*wNotifyCode*/, WORD /*wID*/,
                   HWND /*hWndCtl*/, BOOL& /*bHandled*/);

Therefore, declaring a message, command, or to notify handlers is a trivial task.

Apart from numerous forms, frames, and views, WTL brings a few helper objects that allow you to simplify your code and also make it more structured. <atlapp.h> holds a few useful classes:

  • CMessageLoop: Controls message processing
  • CMessageFilter: Provides a convenient mechanism of message filtering
  • CIdleHandler: Idle periods processing handler

So, you can add a message loop to global the CAppModule _Module variable, and then add or remove desired message filters and so forth.

Using DDX with WTL

If you have things such as edit boxes or other controls on your form or dialog, it is quite likely that you will need to send data back and forth. WTL helps you here and adds its own content to provide DDX support. atlddx.h contains many DDX macros for every purpose. To get DDX functionality, you have to add CWinDataExchange to the parent's list of your dialog or view and put in DDX map macros:

class CWtlFormView : public CDialogImpl<CWtlFormView>,
                     public CWinDataExchange<CWtlFormView>
      DDX_TEXT(IDC_EDIT1, m_sEditText)

   CString m_sEditText;

Those macros declare your class implementation of the DoDataExchange() function, which you will use in the code to exchange data with desired controls:

DoDataExchange(FALSE);    // to copy data to UI control
DoDataExchange(TRUE);     // to get data from UI control

Page 1 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date