天天看點

WTL快速之旅

http://blog.csdn.net/benny5609/article/details/2261102

目标 該章的目标為 <!--[if !supportLists]-->Ÿ       <!--[endif]-->介紹WTL中的模闆(templates)和類(classes) <!--[if !supportLists]-->Ÿ       <!--[endif]-->列舉WTL中沒有包含的特性 <!--[if !supportLists]-->Ÿ       <!--[endif]-->描述諸如WTL名稱空間(namespace)、CRT和錯誤處理(error handling) <!--[if !supportLists]-->Ÿ       <!--[endif]-->列舉WTL的宏(macros) <!--[if !supportLists]-->Ÿ       <!--[endif]-->看一下如何利用AUTOEXP.DAT來改進調試過程 <!--[if !supportLists]-->Ÿ       <!--[endif]-->回顧CRT和WTL的使用 <!--[if !supportLists]-->Ÿ       <!--[endif]-->比較MFC和WTL <!--[if !supportLists]-->Ÿ       <!--[endif]-->涵蓋WTL的CString類   WTL的分發 WTL的分發包有三部分:include目錄下的15個C++頭檔案,WTL AppWizard和sample工程,其中核心的部分在include目錄,AppWizard是用來生成調用定義在頭檔案中的模闆/類的工程的,sample工程是用來說明如何使用這些模闆和類的。你可能會花費數小時的時間來搞清楚AppWizard生成的代碼和哪些sample工程,但是你需要數周的時間來學習定義在那些頭檔案中的模闆和類。 WTL提供了大量的專注于使用者界面(user interface)開發的模闆和類,它們可以和ATL,STL,VC++OLE DB Data templates等其他模闆庫一起使用,并不存在競争者關系。所有這些類加起來可以被看作是MFC和VB的競争者。 在大多數地方,WTL是低層Win32API之上很“薄”的一層封裝,在少數領域(比如,scroll-bars,splitters,print preview)WTL也有實質性的新功能。 除了WTL AppWizard,沒有其他的和DevStudio內建的WTL向導了,我們可以用ATL Windows Message Handler Wizard來添加handlers,但是它們并沒有對WTL’s message crackers。   模闆和類 WTL是C++模闆和類的集合。除了若幹幾個類使用了繼承(比如,CDC,CPaintDC,cWindowDC和CPrintDC)這個别的情況外,WTL的模闆和類是互相獨立的,并沒有公共的“根”,是以沒有所謂的“WTL繼承層次圖”,因為WTL本身就沒有複雜的層次關系。在這一節中我們将對WTL所涉及的功能領域做一個概述,并列舉出可用的模闆和類。我們也将列出那些優雅地包含各自功能領域的頭檔案。 每一個WTL應用程式必須包含atlapp.h,它在内部又包含了atluser.h和atlgdi.h。其他的WTL頭檔案隻有在用到它們所包含的功能時才是必需的。   Application Services(atlapp.h) 這些類提供了子產品(exe或dll)的基本功能和消息循環(message loop)。它們也支援消息過濾(messagefiltering)和空閑處理(idle handling)。 class CAppModule : public CComModule class CServerAppModule : public CAppModule class CMessageLoop class CMessageFilter class CIdleHandler   标準控件(Standard Controls)和通用控件(Common Controls) (atlctrls.h) WTL提供了WindowsOS中每一個标準控件和通用控件的包裝模闆。這些模闆一般是和ATL的CWindow一起使用,是以WTL也為每個控件提供了相應的typedef。在程式中我們一般使用這些typedef出來的值而不是直接使用模闆。這些控件的定義如下: template <class TBase>class CStaticT; typedefCStaticT<CWindow> CStatic; 下面是一個完整的清單: CButtonT           CButton           CTrackBarCtrlT         CTrackBarCtrl CListBoxT          CListBox          CUpDownCtrlT           CUpDownCtrl CComboBoxT         CComboBox         CProgressBarCtrlT      CProgressBarCtrl CEditT             CEdit             CHotKeyCtrlT           CHotKeyCtrl CScrollBarT        CScrollBar        CAnimateCtrlT          CAnimateCtrl CToolTipCtrlT CToolTipCtrl      CRichEditCtrlT         CRichEditCtrl CHeaderCtrlT       CHeaderCtrl       CReBarCtrlT            CReBarCtrl CListViewCtrlT     CListViewCtrl     CMonthCalendarCtrlT    CMonthCalendarCtrl CTreeViewCtrlT     CTreeViewCtrl     CDateTimePickerCtrlT  CDateTimePickerCtrl CToolBarCtrlT CToolBarCtrl      CIPAddressCtrlT        CIPAddressCtrl CStatusBarCtrlT    CStatusBarCtrl    CPagerCtrlT            CPagerCtrl CTabCtrlT          CTabCtrl   這些控件可以用Create方法來建立,但是更多情況下我們用ResourceView建立對話框資源和其中的控件,這時我們可以在代碼中執行個體化一個這些控件模闆然後調用Attach方法來挂接到這些控件上。是以為一個對話框中的list box添加字元串可能使用下面的方法: CListBox m_ListBox; . . . m_ListBox.Attach(GetDlgItem(IDC_LIST_DEMO)); m_ListBox.AddString(TEXT("One")); 注意ATL已經支援ActiveXcontrol containment是以WTL就沒有提供額外的支援。WTL中有一些額外的控件類/模闆來提供額外的功能。WTL的CComboboxEx是Win32ComboBoxEx控件的包裝,它為标準的combobox提供了Image List支援。在WTL中,CComboBoxExT是從CComboBoxT繼承的,并根據需要添加了額外的功能: template <class TBase> class CComboBoxExT : public CComboBoxT< TBase > typedef CComboBoxExT<CWindow> CComboBoxEx; WTL支援“平面風格的滾動條(flat scroll-bars)”,在功能上它們和普通滾動條一樣,但是在外觀上,就像它們的名字,它們是平面風格的,沒有突起的斜面邊界。 template <class T> class CFlatScrollBarImpl template <class TBase> class CFlatScrollBarT :public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase> > typedef CFlatScrollBarT<CWindow> CFlatScrollBar; Treeview控件用來處理HTREEITEM(一個包含tree中各個節點的複雜結構的句柄)。為了簡化對HTREEITEM的處理,WTL提供了CTreeItem類,它提供了置文本、圖檔、資料、狀态資訊和周遊樹的方法。CTreeViewCtrlExT模闆是基于CTreeViewCtrlT模闆的 template <class TBase> class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase > typedef CTreeViewCtrlExT<CWindow> CTreeViewCtrlEx; class CTreeItem; // wrapper for HTREEITEM CTreeViewCtrlExT提供了處理CTreeItem和原始HTREEITEM句柄的方法。比如CTreeViewCtrlT提供了插入item的方法: HTREEITEM InsertItem(LPTV_INSERTSTRUCT lpInsertStruct); 而CtreeViewCtrlExT提供這個方法: CTreeItem InsertItem(LPTV_INSERTSTRUCT lpInsertStruct); Edit boxes和rich-editboxes必需處理一些通用的消息,比如ID_EDIT_COPY, ID_EDIT_CUT,ID_EDIT_PASTE和ID_EDIT_UNDO。有兩個類可以用來自動處理這些消息。 template <class T> class CEditCommands; template <class T> class CRichEditCommands : public CEditCommands< T > 還有管理imagelist和toolinfo的工具類。 class CImageList; class CToolInfo : public TOOLINFO 一個drag-listbox和一個普通的listbox很類似,但是提供了拖動item的功能。CDragListNotifyImpl提供了拖放過程中的消息處理。 template <class TBase> class CDragListBoxT : public CListBoxT< TBase > typedef CDragListBoxT<CWindow> CDragListBox; template <class T> class CDragListNotifyImpl; 一些通用元件可以配置為custom draw來呈現自己的itmes。它們會發送NM_CUSTOMDRAW消息,下面這個WTL模闆就可以為處理這個消息提供幫助: template <class T> class CCustomDraw   Command Bars (atlctrlw.h) 以前我們在程式中用标準的菜單條來向終端使用者提供指令,然後是工具條(toolbar),後來又有了最初随InternetExplorer一起釋出的rebar控件,它為菜單和工具條提供了統一的“容器”。WTL支援一種叫做command bar的控件,但是和Word2000中的有差別。 在WTL中,一個commandbar是一個增強版的menu bar,tool bar仍然要使用。在WTL生成的程式中,command bar個tool bar被分别容納在一個rebar控件的不同band中,band可以在rebar中移動。Command bar(和tool bar)在WTL中是不可“停靠(dockable)”的。 WTL的command bar顯示菜單并在菜單的旁邊顯示對應的工具條圖示,友善了終端使用者。 WTL提供了用于command bar的類: class CCommandBarCtrlBase : public CToolBarCtrl template <class T, class TBase = CCommandBarCtrlBase, class TWinTraits = CControlWinTraits> class CCommandBarCtrlImpl : public CWindowImpl< T, TBase, TWinTraits> class CCommandBarCtrl : public CCommandBarCtrlImpl<CCommandBarCtrl> 當使用WTL AppWizard的預設設定生成一個程式時,你的程式會自動使用command bar而無需你額外的動作。   進階控件(atlctrlx.h) WTL支援更多的進階控件。 CBitmapButton提供了可以顯示imagelist圖檔的pushbutton template <class T, class TBase = CButton, class TWinTraits = CControlWinTraits> class CBitmapButtonImpl : public CWindowImpl< T, TBase, TWinTraits> class CBitmapButton : publicCBitmapButtonImpl<CBitmapButton>   CCkeckListLiew提供了一組checkboxes。 template <DWORD t_dwStyle, DWORD t_dwExStyle, DWORD t_dwExListViewStyle> classCCheckListViewCtrlImplTraits; typedef CCheckListViewCtrlImplTraits<WS_CHILD |WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT> CCheckListViewCtrlTraits; template <class T, class TBase = CListViewCtrl, class TWinTraits = CCheckListViewCtrlTraits> class CCheckListViewCtrlImpl : public CWindowImpl<T, TBase, TWinTraits>; class CCheckListViewCtrl : public CCheckListViewCtrlImpl<CCheckListViewCtrl>;   CHyperLink允許在程式中嵌入web-links,當按下時會打開一個浏覽器顯示這個URL。 template <class T, class TBase = CWindow, class TWinTraits = CControlWinTraits> class CHyperLinkImpl : public CWindowImpl< T, TBase, TWinTraits > class CHyperLink : publicCHyperLinkImpl<CHyperLink>   CWaitCursor可以根據輸入參數設定光标,預設值為IDC_WAIT。 class CWaitCursor   CMultiPaneStatusBarCtrl 提供了一個包含了“子分割”的狀态條(status bar)不同的“分割”上可以放置不同的文本。   template <class T, class TBase = CStatusBarCtrl> class CMultiPaneStatusBarCtrlImpl : public CWindowImpl< T, TBase > class CMultiPaneStatusBarCtrl : publicCMultiPaneStatusBarCtrlImpl<CMultiPaneStatusBarCtrl>   Dynamic Data Exchange(altddx.h) DDX用來在類的資料成員和對話框控件之間雙向交換資料。WTL中的DDX隻牽涉到一個模闆類CWinDataExchange,和許多和宏,比如DDX_TEXT。 template <class T> class CWinDataExchange 要想使用DDX,你的對話框類應該從CDialogImpl和CWinDataExchange繼承并有一個message map,比如 BEGIN_DDX_MAP(CMyDialogDlg) DDX_INT(IDC_AMOUNT_INT, m_nAmount) END_DDX_MAP() 目前這個map必須手工建立,但是很有可能在下一版的Visual C++ Wizard中支援通過向導建立(到目前為止VC7仍然不支援——譯者注)。   System Dialogs And Property Sheets (atldlgs.h) WTL對系統對話框提供了全面的支援 template <class T> class CFileDialogImpl : public CDialogImplBase WTL Developer’s Guide class CFileDialog : publicCFileDialogImpl<CFileDialog> template <class T> class CFolderDialogImpl class CFolderDialog : publicCFolderDialogImpl<CFolderDialog> class CCommonDialogImplBase : public CWindowImplBase template <class T> class CFontDialogImpl : public CCommonDialogImplBase class CFontDialog : publicCFontDialogImpl<CFontDialog> class CRichEditFontDialogImpl : publicCFontDialogImpl< T > class CRichEditFontDialog : public CRichEditFontDialogImpl<CRichEditFontDialog> template <class T> class CColorDialogImpl : public CCommonDialogImplBase class CColorDialog : publicCColorDialogImpl<CColorDialog> template <class T> class CPrintDialogImpl : public CCommonDialogImplBase class CPrintDialog : publicCPrintDialogImpl<CPrintDialog> template <class T> class CPrintDialogExImpl : public CWindow, public CMessageMap, public IPrintDialogCallback, public IObjectWithSiteImpl< T > class CPrintDialogEx : public CPrintDialogExImpl<CPrintDialogEx> template <class T> class CPageSetupDialogImpl : public CCommonDialogImplBase class CPageSetupDialog : public CPageSetupDialogImpl<CPageSetupDialog> template <class T> class CFindReplaceDialogImpl : public CCommonDialogImplBase class CFindReplaceDialog : public CFindReplaceDialogImpl<CFindReplaceDialog>   WTL也為propertysheet提供一系列的支援:   class CPropertySheetWindow : public CWindow template <class T, class TBase =CPropertySheetWindow> class CPropertySheetImpl : public CWindowImplBaseT<TBase > class CPropertySheet : publicCPropertySheetImpl<CPropertySheet> class CPropertyPageWindow : public CWindow template <class T, class TBase =CPropertyPageWindow> class CPropertyPageImpl : public CDialogImplBaseT<TBase > template <WORD t_wDlgTemplateID> classCPropertyPage : public CPropertyPageImpl<CPropertyPage<t_wDlgTemplateID>>   Frames (atlframe.h) 下面的類用來支援frames CFrameWndClassInfo 是frame window的類 class CFrameWndClassInfo CFrameWindowImpl 是程式級用來管理frames的基本C++類 template <class TBase = CWindow, class TWinTraits = CFrameWinTraits> class CFrameWindowImplBase : public CWindowImplBaseT< TBase, TWinTraits > template <class T, class TBase = CWindow, classTWinTraits = CFrameWinTraits> class CFrameWindowImpl : public CFrameWindowImplBase< TBase, TWinTraits >   為了支援MDI,WTL提供了這些類: class CMDIWindow : public CWindow template <class T, class TBase = CMDIWindow, classTWinTraits = CFrameWinTraits> class CMDIFrameWindowImpl : publicCFrameWindowImplBase<TBase, TWinTraits > template <class T, class TBase = CMDIWindow, classTWinTraits = CMDIChildWinTraits> class CMDIChildWindowImpl : public CFrameWindowImplBase<TBase, TWinTraits >   COwnerDraw模闆為實作owner draw功能提供幫助。它通常通過多重繼承來添加到類中的。COwnerDraw和CCustomDraw是有差別的,CCustomDraw處理通過WM_NOTIFY發送的NM_CUSTOMDRAW通知消息。支援這個通知的有下面的通用控件: Headers,list view, rebar,tooltip,trackbar和tree view控件。COwnerDraw處理WM_DRAWITEM,WM_MEASUREITEM,WM_COMPAREITEM和WM_DELETEITEM消息,這些消息一般是發送給owner-draw button,combobox,list view控件或菜單項目(itmes)。 template <class T> class COwnerDraw   CUpdateUI可以用來動态更新UI元素。菜單項目(items)和toolbar按鈕可以用它來實作“可用”和“不可用(禁止)”狀态。 class CUpdateUIBase; template <class T> class CUpdateUI : public CUpdateUIBase   GDI(atlgdi.h) WTL提供了管理所有GDI對象的模闆。每個模闆的邏輯型參數t_bManaged指定這個GDI對象是否在模闆的析構函數裡被删除(delete)。每個模闆有兩個typedefs,其中一個t_bManaged置true,另一個置false。這些模闆包含了所有的win32 GDI APIs,為它們提供了類型安全的(typesafe)C++接口。 template <bool t_bManaged> class CPenT typedef CPenT<false> CPenHandle; typedef CPenT<true> CPen; template <bool t_bManaged> class CBrushT typedef CBrushT<false> CBrushHandle; typedef CBrushT<true> CBrush; template <bool t_bManaged> class CFontT typedef CFontT<false> CFontHandle; typedef CFontT<true> CFont; template <bool t_bManaged> class CBitmapT typedef CBitmapT<false> CBitmapHandle; typedef CBitmapT<true> CBitmap; template <bool t_bManaged> class CPaletteT typedef CPaletteT<false> CPaletteHandle; typedef CPaletteT<true> CPalette; template <bool t_bManaged> class CRgnT typedef CRgnT<false> CRgnHandle; typedef CRgnT<true> CRgn; template <bool t_bManaged> class CDCT typedef CDCT<false> CDCHandle; typedef CDCT<true> CDC;   從CDC還繼承出來一些工具類(helperclasses)用來提供額外的功能。CPaintDC用來處理WM_PAINT消息,它在構造函數裡調用了Win32的BeginPaint,在析構函數裡調用EndPaint。CClientDC和CWindowDC用來取得一個HWND的客戶區和視窗DC。CEnhMetaFileDC用來在一個“增強元檔案(enhanced metafile)中繪畫,它的構造函數調用了Win32的CreateEnhMetaFile,析構函數調用了CloseEnhMetaFile。 class CPaintDC : public CDC class CClientDC : public CDC class CWindowDC : public CDC class CEnhMetaFileDC : public CDC   WTL還為enhanced metafile提供了額外的支援。CEnhMetaFileT是對一個enhanced metafile句柄的包裝。CEnhMetaFileInfo提供了對win32的GetEnhMetaFileBits、GetEnhMetaFileDescription, GetEnhMetaFileHeader 和 GetEnhMetaFilePixelFormat的調用 template <bool t_bManaged> class CEnhMetaFileT typedef CEnhMetaFileT<false> CEnhMetaFileHandle; typedef CEnhMetaFileT<true> CEnhMetaFile; class CEnhMetaFileInfo   其他(atlmisch) WTL還為常用資料類型提供了包裝類。WTL的CString是MFCCString的完美模仿和代替品。還有CSize,CPoint和CRect class CSize : public tagSIZE class CPoint : public tagPOINT class CRect : public tagRECT class CString;   處理最近檔案清單(recent file list)和檔案搜尋 class CRecentDocumentList; class CFindFile;   列印(atlprint.h) WTL為列印提供了很好的支援。 PrinterInfo資料被template <unsigned int t_nInfo> class CPrinterInfo的支援。下面的模闆有來處理列印機句柄: template <bool t_bManaged> class CPrinterT typedef CPrinterT<false> CPrinterHandle; typedef CPrinterT<true> CPrinter;   處理 DEVMODE的模闆 template <bool t_bManaged> class CDevModeT; typedef CDevModeT<false> CDevModeHandle; typedef CDevModeT<true> CDevMode;   向列印機繪畫是使用這個DC類: class CPrinterDC : public CDC   要獲得列印任務(job)的資訊,使用 class IPrintJobInfo class CPrintJobInfo : public IPrintJobInfo class CPrintJob;   列印預覽視窗 class CPrintPreview; template <class T, class TBase = CWindow, classTWinTraits = CControlWinTraits> class CPrintPreviewWindowImpl :public CWindowImpl<T, TBase, TWinTraits>, publicCPrintPreview class CPrintPreviewWindow : publicCPrintPreviewWindowImpl<CPrintPreviewWindow>   滾動(Scrolling)(atlscrl.h) 視窗滾動是被下面這些類和模闆支援的: template <class T> class CScrollImpl template <class T, class TBase = CWindow, class TWinTraits = CControlWinTraits> class CScrollWindowImpl :public CWindowImpl<T,TBase,TWinTraits>,publicCScrollImpl< T > template <class T> class CMapScrollImpl: publicCScrollImpl< T > template <class T, class TBase = CWindow, class TWinTraits = CControlWinTraits> class CMapScrollWindowImpl : public CWindowImpl< T,TBase, TWinTraits >, public CMapScrollImpl< T >   平面分割的滾動條: template <class TBase = CWindow> class CFSBWindowT :public TBase, public CFlatScrollBarImpl<CFSBWindowT<TBase > > typedef CFSBWindowT<CWindow> CFSBWindow;   分割條(splitters)(atlsplit.h) 水準和垂直的分割條可以用下面的三個模闆實作: template <class T, bool t_bVertical = true> classCSplitterImpl; template <class T, bool t_bVertical = true, classTBase = CWindow, class TWinTraits = CControlWinTraits> class CSplitterWindowImpl : public CWindowImpl< T,TBase, TWinTraits >, public CSplitterImpl<CSplitterWindowImpl< T ,t_bVertical, TBase, TWinTraits >, t_bVertical> template <bool t_bVertical = true> classCSplitterWindowT : public CSplitterWindowImpl< CSplitterWindowT<t_bVertical>, t_bVertical> typedef CSplitterWindowT<true> CSplitterWindow; typedef CSplitterWindowT<false> CHorSplitterWindow;   菜單(atluser.h) CMenuItemInfo類是Win32中MENUITEMINFO結果的包裝,CMenuT可以用來管理菜單,它提供了對菜單所有屬性的類型安全的通路。 class CMenuItemInfo : public MENUITEMINFO template <bool t_bManaged> class CMenuT   WTL中沒有什麼?   (本節翻譯内容并沒有完全照搬原文,和原文相比有所删略。——譯者注) 在看了WTL中的主要功能後,我們來看看WTL不支援的東西。 WTL的唯一目标是為開發人員提供使用者界面,在這方面它已經做得非常好了。它并沒有偏離該目标而設計其他領域。   沒有Document支援 WTL提供了frame和view,但是沒有document。WTL所關注的是使用者界面,而document是不可見的,是以它不是WTL關心的範圍。   沒有Active Document支援 …… 沒有ISAPI支援 …… 沒有WinInet支援 …… 沒有對線程和同步進行包裝 …… 沒有資料庫支援 ……   開發的問題 要開始使用WTL,還有下面幾個問題需要了解。 最終産品 使用WTL建立的程式體積是很小的,AppWizard生成的預設SDI程式編譯後的exe檔案大小隻有64K,TinyWTL例程由于去掉了多餘的功能,編譯後隻有24K大小。一個真實的商業級程式應該不會超過250K。并且這些檔案經過壓縮後将會再減少2/3的體積,可以在Internet上快速下載下傳。 在Build完成後,如果你沒有使用CRT和其他的DirectX之類的庫,那麼WTL工程編譯後的exe或dll就是你唯一需要發送給最終使用者的檔案了。WTL程式沒有額外的依賴。檔案少,出現問題的幾率就少。   CRT C-Runtime library上Win32 API之上的一組C函數,通常被稱作CRT。CRT的源代碼是VC++的一部分(在src目錄),如果你仔細看一下的話,就會發現這些CRT的函數是用ANSI C實作的,一些直接調用了APIs,一些通過調用中間函數間接調用了APIs。CRT大部分是來自ANSI C标準庫的一些函數(printf,strok等),但是也有一些Win32平台相關的函數(比如(beginthreadex在做了一些CRT初始化後調用了CreateThread API) 如果你的程式隻使用ANSI C标準庫,你的代碼就是可移植的。有許多百萬行代碼級的工程在經過不到2%的更改後就可以在Windows和UNIX上順利通過編譯和正常運作。CRT确實在某些領域提供了Win32所沒有的功能,比如string形式的浮點數、C++異常和為全局變量調用構造/析構函數。 如果你使用ATL和WTL進行程式設計,你的代碼絕對不可能移植到UNIX/LINUX之上,這樣有個問題就産生了,我到底有必要連接配接到CRT嗎?CRT在很大程度上是Win32 APIs的重複,是以大部分情況下,大案是“No”。離開了C++異常處理和全局變量的構造/析構函數,也可以生存,而使用了CRT,你的程式體積将增大,并有了額外的外部依賴(MSVCRT.dll)而這個庫有多個版本,這也可能成為麻煩的根源。 WTLAppWizard生成的工程的設定使得CRT在debugbuild是可用(為了調用ATLASSERT),而在releasebuild時并不包含進來(預處理指令中的_ATL_MIN_CRT宏)。如果你沒有注意到這個細節,可能會對“使用了CRT的WTL工程怎麼也無法在release模式下編譯通過”的問題束手無策。注意:CRT在Release模式下預設是不被包含的。   如果你真的打算使用CRT,隻要去掉_ATL_MIN_CRT宏就可以了,(VC7中是把“項目”->“屬性”對話框中的“在ATL中最小使用CRT”選項置“否”)。   如果使用了CRT,關于多線程的一個有趣的問題就産生了。CRT有多個版本,一些是靜态連接配接的,一些的動态加載的,一些是用于單線程應用程式的,一些是用于多線程程式的。如果你在不止一個線程中使用CRT,你就必須使用多線程版本的CRT。同一個工程中的所有EXE和DLL也必須使用一緻的設定(在DevStudio的 Project settings對話框的Generation類别裡)。   錯誤處理 (本段翻譯有删略——譯者注) 在WTL程式中要使用C++異常處理,就必須依賴CRT(當然,如果你願意可以使用)。另外對API可以使用GetLastError和ATLASSERT   WTL名稱空間(namespace) 新的ISO C++标準引入了名稱空間的概念,WTL為了避免和其他類庫産生名稱沖突,它的每一個頭檔案都是以下面的代碼開始: namespace WTL { 并以: }; //namespace WTL 結束 …… …… (省略關于名稱空間的使用的說明——譯者)   模闆/類/方法名   WTL的命名管理沿用MFC的,由于它們兩個都是基于Win32 API的,是以這麼做是有意義的。并且多數的WTL程式員是來自MFC程式員。 WTL的類名是這樣的,CEdit,CStatic和CDC。視窗消息的處理程式名稱為OnInitDialog andOnOK。資料交換使用DDX,方法名為DoDataExchange。 WTL和MFC不同的地方是,在有些地方,WTL明智地遵循了Win32的名稱,比如Win32的UpDown控件在WTL中為CUpDownCtrlT,而在MFC中為CSpinButtonCtrl。   Windows的版本 WTL全面支援Win2000和WinMe(以及Windows XP——譯者)中的新UI特性,但也可以用于舊版本的Windows,這個可以通過#define一個WINVER來實作。   待續……