WTL开发者指南 第4章-WTL快速之旅(2)

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

CHyperLink允许在程序中嵌入web-links,当按下时会打开一个浏览器显示这个URL

template <class T, class TBase = CWindow,

class TWinTraits = CControlWinTraits>

class CHyperLinkImpl

: public CWindowImpl< T, TBase, TWinTraits >

class CHyperLink : public CHyperLinkImpl<CHyperLink>

 

CWaitCursor可以根据输入参数设置光标,默认值为IDC_WAIT

class CWaitCursor

 

CMultiPaneStatusBarCtrl 提供了一个包含了“子分割”的状态条(status bar)不同的“分割”上可以放置不同的文本。

 

template <class T, class TBase = CStatusBarCtrl>

class CMultiPaneStatusBarCtrlImpl

: public CWindowImpl< T, TBase >

class CMultiPaneStatusBarCtrl

: public CMultiPaneStatusBarCtrlImpl<CMultiPaneStatusBarCtrl>

 

Dynamic Data Exchangealtddx.h

DDX用来在类的数据成员和对话框控件之间双向交换数据。WTL中的DDX只牵涉到一个模板类CWinDataExchange,和许多和宏,比如DDX_TEXT

template <class T> class CWinDataExchange

要想使用DDX,你的对话框类应该从CDialogImplCWinDataExchange继承并有一个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 Developers Guide

class CFileDialog : public CFileDialogImpl<CFileDialog>

template <class T> class CFolderDialogImpl

class CFolderDialog : public CFolderDialogImpl<CFolderDialog>

class CCommonDialogImplBase : public CWindowImplBase

template <class T> class CFontDialogImpl

: public CCommonDialogImplBase

class CFontDialog : public CFontDialogImpl<CFontDialog>

class CRichEditFontDialogImpl : public CFontDialogImpl< T >

class CRichEditFontDialog : public

CRichEditFontDialogImpl<CRichEditFontDialog>

template <class T> class CColorDialogImpl

: public CCommonDialogImplBase

class CColorDialog : public CColorDialogImpl<CColorDialog>

template <class T> class CPrintDialogImpl

: public CCommonDialogImplBase

class CPrintDialog : public CPrintDialogImpl<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也为property sheet提供一系列的支持:

 

class CPropertySheetWindow : public CWindow

template <class T, class TBase = CPropertySheetWindow>

class CPropertySheetImpl : public CWindowImplBaseT< TBase >

class CPropertySheet : public CPropertySheetImpl<CPropertySheet>

class CPropertyPageWindow : public CWindow

template <class T, class TBase = CPropertyPageWindow>

class CPropertyPageImpl : public CDialogImplBaseT< TBase >

template <WORD t_wDlgTemplateID> class CPropertyPage

: 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, class TWinTraits =

CFrameWinTraits> class CFrameWindowImpl

: public CFrameWindowImplBase< TBase, TWinTraits >

 

为了支持MDIWTL提供了这些类:

class CMDIWindow : public CWindow

template <class T, class TBase = CMDIWindow, class TWinTraits =

CFrameWinTraits>

class CMDIFrameWindowImpl : public CFrameWindowImplBase<TBase,

TWinTraits >

template <class T, class TBase = CMDIWindow, class TWinTraits =

CMDIChildWinTraits> class CMDIChildWindowImpl

: public CFrameWindowImplBase<TBase, TWinTraits >

 

COwnerDraw模板为实现owner draw功能提供帮助。它通常通过多重继承来添加到类中的。COwnerDrawCCustomDraw是有区别的,CCustomDraw处理通过WM_NOTIFY发送的NM_CUSTOMDRAW通知消息。支持这个通知的有下面的通用控件:

Headerslist view rebartooltiptrackbartree view控件。COwnerDraw处理WM_DRAWITEMWM_MEASUREITEMWM_COMPAREITEMWM_DELETEITEM消息,这些消息一般是发送给owner-draw buttoncomboboxlist 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_bManagedtrue,另一个置false。这些模板包含了所有的win32 GDI APIs,为它们提供了类型安全的(typesafeC++接口。

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还继承出来一些工具类(helper classes)用来提供额外的功能。CPaintDC用来处理WM_PAINT消息,它在构造函数里调用了Win32BeginPaint,在析构函数里调用EndPaintCClientDCCWindowDC用来取得一个HWND的客户区和窗口DCCEnhMetaFileDC用来在一个“增强元文件(enhanced metafile)中绘画,它的构造函数调用了Win32CreateEnhMetaFile,析构函数调用了CloseEnhMetaFile

class CPaintDC : public CDC

class CClientDC : public CDC

class CWindowDC : public CDC

class CEnhMetaFileDC : public CDC

 

WTL还为enhanced metafile提供了额外的支持。CEnhMetaFileT是对一个enhanced metafile句柄的包装。CEnhMetaFileInfo提供了对win32GetEnhMetaFileBitsGetEnhMetaFileDescription,

GetEnhMetaFileHeader GetEnhMetaFilePixelFormat的调用

template <bool t_bManaged> class CEnhMetaFileT

typedef CEnhMetaFileT<false> CEnhMetaFileHandle;

typedef CEnhMetaFileT<true> CEnhMetaFile;

class CEnhMetaFileInfo

 

其他(atlmisch

WTL还为常用数据类型提供了包装类。WTLCStringMFC CString的完美模仿和代替品。还有CSizeCPointCRect

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, class TWinTraits =

CControlWinTraits>

class CPrintPreviewWindowImpl

:public CWindowImpl<T, TBase, TWinTraits>, public CPrintPreview

class CPrintPreviewWindow

: public CPrintPreviewWindowImpl<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>,public CScrollImpl< T >

template <class T> class CMapScrollImpl: public CScrollImpl< 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> class CSplitterImpl;

template <class T, bool t_bVertical = true, class TBase =

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> class CSplitterWindowT

: public CSplitterWindowImpl<

CSplitterWindowT<t_bVertical>, t_bVertical>

typedef CSplitterWindowT<true> CSplitterWindow;

typedef CSplitterWindowT<false> CHorSplitterWindow;

 

菜单(atluser.h

CMenuItemInfo类是Win32MENUITEMINFO结果的包装,CMenuT可以用来管理菜单,它提供了对菜单所有属性的类型安全的访问。

class CMenuItemInfo : public MENUITEMINFO

template <bool t_bManaged> class CMenuT

 

WTL中没有什么?

 

(本节翻译内容并没有完全照搬原文,和原文相比有所删略。——译者注)

在看了WTL中的主要功能后,我们来看看WTL不支持的东西。

WTL的唯一目标是为开发人员提供用户界面,在这方面它已经做得非常好了。它并没有偏离该目标而设计其他领域。

 

没有Document支持

WTL提供了frameview,但是没有documentWTL所关注的是用户界面,而document是不可见的,所以它不是WTL关心的范围。

 

没有Active Document支持

……

没有ISAPI支持

……

没有WinInet支持

……

没有对线程和同步进行包装

……

没有数据库支持

……

 

开发的问题

要开始使用WTL,还有下面几个问题需要理解。

最终产品

使用WTL建立的程序体积是很小的,AppWizard生成的默认SDI程序编译后的exe文件大小只有64KTinyWTL例程由于去掉了多余的功能,编译后只有24K大小。一个真实的商业级程序应该不会超过250K。并且这些文件经过压缩后将会再减少2/3的体积,可以在Internet上快速下载。

Build完成后,如果你没有使用CRT和其他的DirectX之类的库,那么WTL工程编译后的exedll就是你唯一需要发送给最终用户的文件了。WTL程序没有额外的依赖。文件少,出现问题的几率就少。

 

CRT

C-Runtime libraryWin32 API之上的一组C函数,通常被称作CRTCRT的源代码是VC++的一部分(在src目录),如果你仔细看一下的话,就会发现这些CRT的函数是用ANSI C实现的,一些直接调用了APIs,一些通过调用中间函数间接调用了APIsCRT大部分是来自ANSI C标准库的一些函数(printfstrok等),但是也有一些Win32平台相关的函数(比如(beginthreadex在做了一些CRT初始化后调用了CreateThread API

如果你的程序只使用ANSI C标准库,你的代码就是可移植的。有许多百万行代码级的工程在经过不到2%的更改后就可以在WindowsUNIX上顺利通过编译和正常运行。CRT确实在某些领域提供了Win32所没有的功能,比如string形式的浮点数、C++异常和为全局变量调用构造/析构函数。

如果你使用ATLWTL进行编程,你的代码绝对不可能移植到UNIX/LINUX之上,这样有个问题就产生了,我到底有必要连接到CRT吗?CRT在很大程度上是Win32 APIs的重复,所以大部分情况下,大案是“No”。离开了C++异常处理和全局变量的构造/析构函数,也可以生存,而使用了CRT,你的程序体积将增大,并有了额外的外部依赖(MSVCRT.dll)而这个库有多个版本,这也可能成为麻烦的根源。

WTL AppWizard生成的工程的设置使得CRTdebug build是可用(为了调用ATLASSERT),而在release build时并不包含进来(预处理指令中的_ATL_MIN_CRT)。如果你没有注意到这个细节,可能会对“使用了CRTWTL工程怎么也无法在release模式下编译通过”的问题束手无策。注意:CRTRelease模式下默认是不被包含的。

 

如果你真的打算使用CRT,只要去掉_ATL_MIN_CRT宏就可以了,(VC7中是把“项目”->“属性”对话框中的“在ATL中最小使用CRT”选项置“否”)。

 

如果使用了CRT,关于多线程的一个有趣的问题就产生了。CRT有多个版本,一些是静态连接的,一些的动态加载的,一些是用于单线程应用程序的,一些是用于多线程程序的。如果你在不止一个线程中使用CRT,你就必须使用多线程版本的CRT。同一个工程中的所有EXEDLL也必须使用一致的设置(在DevStudio Project settings对话框的Generation类别里)。

 

错误处理

(本段翻译有删略——译者注)

WTL程序中要使用C++异常处理,就必须依赖CRT(当然,如果你愿意可以使用)。另外对API可以使用GetLastErrorATLASSERT

 

WTL名称空间(namespace

新的ISO C++标准引入了名称空间的概念,WTL为了避免和其他类库产生名称冲突,它的每一个头文件都是以下面的代码开始:

namespace WTL

{

并以:

}; //namespace WTL

结束

……

……

(省略关于名称空间的使用的说明——译者)

 

模板//方法名

 

WTL的命名管理沿用MFC的,由于它们两个都是基于Win32 API的,所以这么做是有意义的。并且多数的WTL程序员是来自MFC程序员。

WTL的类名是这样的,CEditCStaticCDC。窗口消息的处理程序名称为OnInitDialog and OnOK。数据交换使用DDX,方法名为DoDataExchange

WTLMFC不同的地方是,在有些地方,WTL明智地遵循了Win32的名称,比如Win32UpDown控件在WTL中为CUpDownCtrlT,而在MFC中为CSpinButtonCtrl

 

Windows的版本

WTL全面支持Win2000WinMe(以及Windows XP——译者)中的新UI特性,但也可以用于旧版本的Windows,这个可以通过#define一个WINVER来实现。

 
从零开始的WTL入门教程(1) WTL的简介,环境搭建 图文手把手教学系列 阅读详情

相关推荐

WTL界面介绍

前 言 WTL 全称是 Windows Template Library,像 MFC 一样使用 C++ 的面向对象技术对 Win32 接口进行了封装,使之便于开发 Windows 程序。相对于 MFC 这个庞然大物,WTL 保持了小而美,只包含了界面开发相关的特性。 如果想在vs 2019 上安装wtl ,可以使用看如下文: https://www.cnblogs.com/Lzl678/p/10771668.html WTL概述 WTLWindows Template Library 的缩写。最初,W

houxian1103的博客 3605

RichEditDemo(WTL)

1、支持输入框文字格式设置,包括字体名称、字体大小、加粗、倾斜、下划线、文字颜色等。 2、支持插入BMP、JPG、PNG、GIF等格式的图片文件。 3、支持图片和文字的复制剪切粘贴拖放,并与QQ、IE、Google Chrome、Word等的剪切板格式互相兼容。 4、支持表情选择框、图片文件选择框等方式插入表情或图片。 5、支持设置显示比例,图片自动缩放,图片右键另存为菜单,图片双击打开,图片悬浮工具栏等。

Windows Template Library(WTL)7.1和7.5版本合集及使用指南

本文还有配套的精品资源,点击获取 简介:WTL合集(7.1和7.5).rar 是一个为Visual C++ 6.0用户提供的包含WTL版本7.1和7.5的压缩包。WTL是Microsoft开发的C++库,用于构建轻量级、高效的Windows应用程序,包括系统组件和控制台程序。WTL7.1提供基本类和功能,支持旧版Windows API;WTL7.5则可能包含性能优化、新控件...

weixin_35835030的博客 1044

ATL与WTL精品学习资料.rar

ATL与WTL精品学习资料.rar

[翻译]WTL开发者指南4WTL快速之旅(2)

接上篇http://blog.csdn.net/uoyevoli/archive/2005/11/25/536879.aspxCHyperLink允许在程序中嵌入web-links,当按下时会打开一个浏览器显示这个URL。template class TWinTraits = CControlWinTraits>class CHyperLinkImpl: p

farproc's blog 5262

WTL 界面设计篇(CSkinRichEdit)

头文件声明(CSkinRichEdit.h): #pragma once #include <textserv.h> #include <richedit.h> #include "SkinScrollBar.h" class CSkinRichEdit; /* * TXTEFFECT * * @enum Defines different background styles control */ enum TXTEFFECT { TXTEFFECT_NONE =

老狼的专栏 1044

[翻译]WTL开发者指南 第1 WTL概述

WTL开发者指南注:本文是袁晓辉根据Eamon O’ Tuathail的WTL Developer’s Guide(www.clipcode.biz ) 翻译而来,发布在www.farproc.com 和 blog.csdn.net。作者翻译本文仅仅是为自己和其他WTL爱好者学习之用,请勿用于商业用途。你可以转载本文,但必须保证本文的完整性,并保留该声明! 第1 WTL概述目标该的目标为:Ÿ 

farproc's blog 7228

[翻译]WTL开发者指南4WTL快速之旅(1)

接上篇:http://blog.csdn.net/uoyevoli/archive/2005/05/30/384357.aspx第4WTL快速之旅目标该的目标为Ÿ       介绍WTL中的模板(templates)和类(classes)Ÿ       列举WTL中没有包含的特性Ÿ       描述诸如WTL名称空间(namespace)、CR

farproc's blog 6275

4WTL快速之旅

4WTL快速之旅 目标该的目标为Ÿ       介绍WTL中的模板(templates)和类(classes)Ÿ       列举WTL中没有包含的特性Ÿ       描述诸如WTL名称空间(namespace)、CRT和错误处理(error handling)Ÿ       列举WTL的宏(macros)Ÿ       看一下如何利用AUTOEXP.DAT来改

1047

114页的WTL指南WTL7.1

114页的MFC程序员的WTL开发指南(word)WTL7.1.exe

深入剖析WTL

此文件深入讲解了wtl的有关知识,及其开发。希望对大家有帮助。

WTL doc

很不错的关于WTL开发的文档

WTL

1.支持 VS 2008 的 WTL Helper  支持 VS 2008 的 WTL Helper 等了两年, 那个白俄还是没有更新 wtl helper, 实在难以忍受了, 将人家的东东改了改, 重新发布在我的自留地里. 下载地址, 可执行安装包:  http://www.cppblog.com/Files/free2000fly/WTL

okadler0518的专栏 6444

MFC程序员的WTL指南: 中文版序言

MFC程序员的WTL指南: 中文版序言作者:Orbit (www.winmsg.com)我一直在寻找这样一个类库:他对Windows的窗口提供面向对象的封装,有灵活的消息响应机制和比较完备的界面框架解决方案,对标准控件提供简练实用的封装,支持操作系统的新特性,支持功能扩充和二次开发,有代码自动生成向导机制,生成的程序使用较少的系统资源,最后是有完全的代码支持和文档支持。 你会说那就用MFC吧!

lithe的Blog 1797

WTL学习指南

WTL学习资料非常少,最要命的是WTL没有官方支持,所以记录一下,给WTL学习的同学一点参考,少走弯路. 我的情况: 一个人开发Windows 客户端,除了网络,没有任何技术支持。以前开发过嵌入式Linux开发,基本不和界面打交道,知道一些Windows编程要素,也了解MFC,其他无任何Windows开发经验,也从来没有开发过一个Windows程序。目前需要开发一个Windows的支持拖拽

etwdone的专栏 1134

初识WTL

代码运行效果图如下: 1.前言 虽然MFC的功能很强大,但Windows Template Library(WTL)的出现,无疑说明了MFC有一定的弊病。和MFC相比,功能并没有MFC完善。比如MFC支持doc/view架构,而WTL并不支持。同时,WTL也没有Microsoft的官方支持。但是,WTL是基于模版(template)的,其应用程序最小只有24KB,同时不象MFC,依赖D

有梦,有追求 1万+

WTL基础入门

WTLWindows Template Library,提供了一套用于Windows的组件,由于体积很小,而且生成的exe也很小,所以做一些测试软件就十分经济。

微小冷的学习笔记 4295
上一篇: GRETA正则表达式模板类库
下一篇: CVTRES : fatal error CVT1100: duplicate resource -- type:MANIFEST, name:1, language:0x0409
一劳永逸
博客等级 码龄20年 101粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值