ATL一:CWindowImpl
1,
#ifdef _ATL_DISABLE_NO_VTABLE
#define ATL_NO_VTABLE
#else
#define ATL_NO_VTABLE __declspec(novtable)
#endif
This form of __declspec can be applied to any class declaration, but should only be applied to pure interface classes, that is, classes that will never be instantiated on their own. The __declspec stops the compiler from generating code to initialize the vfptr in the constructor(s) and destructor of the class. In many cases, this removes the only references to the vtable that are associated with the class and, thus, the linker will remove it. Using this form of __declspec can result in a significant reduction in code size.
__declspec(novtable)最好只用于纯虚接口函数,永远不能对自己实例化。它阻止编译器在类构造和析构的时候初始化虚函数表。通常,在链接的时候会删除虚函数表。这样做可以显著减少代码大小。(总之就是不产生虚函数表,减少运行时间和空间。应为没有虚函数表,不能对虚函数调用,所以这个类不能生在实例。)
If you attempt to instantiate a class marked with novtable and then access a class member, you will receive an access violation (AV).
2,
// CMessageMap - abstract class that provides an interface for message maps
class ATL_NO_VTABLE CMessageMap
{
public:
virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
LRESULT& lResult, DWORD dwMsgMapID) = 0;
};//消息处理的接口
// CWindowImpl - Implements a window
template <class TBase /* = CWindow */>
class ATL_NO_VTABLE CWindowImplRoot : public TBase, public CMessageMap
{
//消息过滤
}
template <class TBase = CWindow, class TWinTraits = CControlWinTraits>
class ATL_NO_VTABLE CWindowImplBaseT : public CWindowImplRoot< TBase >
{
//创建销毁窗口、设置style、默认消息回调函数
}
template <class T, class TBase /* = CWindow */, class TWinTraits /* = CControlWinTraits */>
class ATL_NO_VTABLE CWindowImpl : public CWindowImplBaseT< TBase, TWinTraits >
{
//设置窗口属性,创建窗口
};
3,
// CWndClassInfo - Manages Windows class information
#define DECLARE_WND_CLASS(WndClassName) \
static ATL::CWndClassInfo& GetWndClassInfo() \
{ \
static ATL::CWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, WndClassName, NULL }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
}; \
return wc; \
}
// Message map
#define BEGIN_MSG_MAP(theClass) \
public: \
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0) \
{ \
BOOL bHandled = TRUE; \
(hWnd); \
(uMsg); \
(wParam); \
(lParam); \
(lResult); \
(bHandled); \
switch(dwMsgMapID) \
{ \
case 0:
#define MESSAGE_RANGE_HANDLER(msgFirst, msgLast, func) \
if(uMsg >= msgFirst && uMsg <= msgLast) \
{ \
bHandled = TRUE; \
lResult = func(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define END_MSG_MAP() \
break; \
default: \
ATLTRACE(ATL::atlTraceWindowing, 0, _T("Invalid message map ID (%i)\n"), dwMsgMapID); \
ATLASSERT(FALSE); \
break; \
} \
return FALSE; \
}
---------------------------------------------------------------------
4,
template< class THost >
class CSingleThreadWindow : public CWindowImpl< CSingleThreadWindow< THost > >
{
public:
DECLARE_WND_CLASS( _T("SingleThreadWindowClass") )
BEGIN_MSG_MAP( CSingleThreadProxy< THost > )
MESSAGE_RANGE_HANDLER(0, 0xFFFFFFFF, WndProc)
END_MSG_MAP()
CSingleThreadWindow( THost *pHost ,BOOL bHeap ){}
RESULT WndProc( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
return m_pHost->OnSingleThreadProxyMsg( uMsg, wParam, lParam, bHandled );
};
protected:
THost *m_pHost;
}
HWND CMulThreadProxy::GetMsgWindow()
{
CSingleThreadWindow<CMulThreadProxy> *pObjWindow = new CSingleThreadWindow<CMulThreadProxy>(this,TRUE);
}
ATL一:CWindowImpl的更多相关文章
- ATL封装IE内核启示:使用Win32/ATL建立窗口
开发大型GUI界面程序MFC当仁不让,但如果是开发图形应用程序,并不需要大规模界面控件,没有必要链接庞大的MFC库,直接使用platform sdk会很麻烦,这时ATL中的关于Windows的封装就是 ...
- ATL中窗口句柄与窗口过程的关联方法
ATL中采用了一种动态生成机器指令的方式进行窗口句柄与窗口对象进行关联,以是详细分析: CWindowImpl会在第一次调用Create时注册窗口类,该窗口类是的信息是在CWindowImpl的子类中 ...
- 认识ATL窗口
这是一个相当于“Hello world!”的任务,作为认识ATL,考查了其运作流程与机制. 环境:VS2008 创建:新建-项目-Win32项目-添加公用头文件用于(选择ATL). PS:注意新建项目 ...
- STL,ATL,WTL之间的联系和区别
STL即 Standard Template Library (标准模板库) STL是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov.Meng Lee和David R M ...
- 使用Win32/ATL建立窗口的过程
有时候想写个几十kb的小程序,MFC实在是太大了,Win32有时又太麻烦,怎么办呢?用ATL写会更方便和轻量级一些 ATL和MFC不同的是,ATL并没有强制性封装WinMain函数,仅封装了WndPr ...
- STL,ATL,WTL的联系与区别
STL 即 Standard Template Library STL(标准模板库)是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov. ...
- 用ATL和MFC来创建ActiveX控件
摘要:目前MFC和ATL代表了两种框架,分别面向不同类型的基于Windows的开发.MFC代表了创建独立的Windows应用的一种简单.一致的方法:ATL提供了一种框架来实现创建COM客户机和服务器所 ...
- ATL CAxWindow类创建问题一则
查看一个浏览器源码实现,发现其中使用了ie的控件,但例子中没有找到任何创建ie浏览器控件的代码,经过仔细跟踪,发现CAxWindow类是可以这么使用滴.. 创建的时候第三个参数直接传入url.调用到C ...
- ATL Thunk机制深入分析
如果你有SDK的编程经验,就一定应该知道在创建窗口时需要指定窗口类,窗口类中的一种重要的参数就是窗口过程.任何窗口接收到的消息,都是由该窗口过程来处理. 在面向对象编程中,如果还需要开发人员来使用原始 ...
随机推荐
- Struts2 学习笔记 11 Result part2
之前学习了result type 和global result 我们现在来说一下 1.Dynamic Result动态结果集.先来看一下小项目的目录 首页的两个链接访问user/user?type=1 ...
- WPF UI布局之概述
在线演示:http://v.youku.com/v_show/id_XNzA5NDk2Mjcy.html 清晰版视频+代码下载:http://115.com/lb/5lbeer0m9lad 一.简单介 ...
- iOS开发——UI_swift篇&UITableView实现单元格展开与隐藏
UITableView实现单元格展开与隐藏 关于UITableView的展开的收缩在前面的文章我已经结束,就是使用代理,通知,block传值的时候实现的,当时是使用一个Bool值来实现,最后使用着三 ...
- sql优化-隐形转换危害
level 整形字段 a:select * form t_user where level =2; b:select * form t_user where level ='2'; b里面的隐形字段 ...
- 1015. Reversible Primes (20)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1015 this pro ...
- Linux内核--网络栈实现分析(二)--数据包的传递过程--转
转载地址http://blog.csdn.net/yming0221/article/details/7492423 作者:闫明 本文分析基于Linux Kernel 1.2.13 注:标题中的”(上 ...
- mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap【转】
由于mybatis简单易学,比起Hibername来,更容易上手,代码也能自动生成.这几天研究了下代码自动生成的,参考: http://0609xiaohua.iteye.com/blog/14535 ...
- 【报错】"The constructor Notification(int, CharSequence, long) is deprecated
Notification的构造方法 Notification(int, CharSequence, long) 在API11之后就淘汰了,之后的API需要用Notification.Builder() ...
- scope重定义
.directive('myAttr', function() { return { restrict: 'E', scope: { customerInfo: '=info' }, template ...
- HBase的JavaAPI操作
如果是DDL的操作就找HbaseAdmin. 如果是表上的增删改查的操作就找HTable. 附录代码: mport java.util.Arrays; import org.apache.hadoop ...