ATL.SubclassWindow分析
[B]ATL.SubclassWindow分析[/B]
[template
BOOL CWindowImplBaseT< TBase, TWinTraits >::SubclassWindow(HWND hWnd)
{ BOOL result;
ATLASSUME(m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
// Allocate the thunk structure here, where we can fail gracefully.
//初始化this 指针与winProc result = m_thunk.Init(GetWindowProc(), this);
if (result == FALSE)
{ return FALSE;
} WNDPROC pProc = m_thunk.GetWNDPROC();
//取得要subclassWindwo的WinProc WNDPROC pfnWndProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)pProc);
if(pfnWndProc == NULL)
return FALSE;
//把取得的Windproc 去sub上 m_pfnSuperWindowProc = pfnWndProc;
//并把本身的m_hWnd 换成要sub上的hWnd m_hWnd = hWnd;
return TRUE;
}
从上面分析可以看出做的步骤有:
[B]1.sub资源上的wndProc
2.sub资源上的hWnd[/B]
BOOL CWindowImplBaseT< TBase, TWinTraits >::SubclassWindow(HWND hWnd)
{ BOOL result;
ATLASSUME(m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
// Allocate the thunk structure here, where we can fail gracefully.
//初始化this 指针与winProc result = m_thunk.Init(GetWindowProc(), this);
if (result == FALSE)
{ return FALSE;
} WNDPROC pProc = m_thunk.GetWNDPROC();
//取得要subclassWindwo的WinProc WNDPROC pfnWndProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)pProc);
if(pfnWndProc == NULL)
return FALSE;
//把取得的Windproc 去sub上 m_pfnSuperWindowProc = pfnWndProc;
//并把本身的m_hWnd 换成要sub上的hWnd m_hWnd = hWnd;
return TRUE;
}
从上面分析可以看出做的步骤有:
[B]1.sub资源上的wndProc
2.sub资源上的hWnd[/B]