现在的位置: 首页 > 综合 > 正文

WTL

2012年08月28日 ⁄ 综合 ⁄ 共 1678字 ⁄ 字号 评论关闭

 

 

 

 

StartWindowProc is a static member function of CWindowImplBase. Its job is to establish the mapping between the CWindowImpl-derived object's HWND and the object's this pointer.

Mapping between HWND and an object's this pointer is done by the StartWindowProc

 

static StartWindowProc 和 static WinProc 都是 CWindowImplBaseT 的成员。

其中,StartWindowProc在RegisterClassEx的时候被设为整个程序的消息处理函数。

 

CWindowImplBaseT在Create的时候,把This指针缓存到一个全局变量中

 

static 的StartWindowProc在第一次被调用的时候,从刚才的全局变量得到This指针,用Trunk产生一个代理的窗口处理函数指针,这个东西会将消息函数调用时的HWND域强制写入pThis

 

 

ATL中的Trunk :

MOV指令将堆栈中的HWND参数(esp+0x4)变成类的实例指针pThis。

JMP指令完成一个相对跳转到实际的窗口函数WndProc的任务。

 

static的WinProc从HWND参数域中得到pThis,当然是这样:pThis = (CWindowImplBaseT*)hWnd;

 

然后pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);语句,也就是调用消息逻辑处理,将具体的消息处理事务交给ProcessWindowMessage()。

接下来,如果ProcessWindowMessage()没有对任何消息进行处理,就调用缺省的消息处理。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

抱歉!评论已关闭.