MFC的消息流动
本文分析MFC4.0的消息流动,从注册消息处理函数到窗口接受到消息的处理过程;
MFC中MessageMap用到的数据类型
struct AFX_MSGMAP
{
AFX_MSGMAP* pBaseMessageMap;
AFX_MSGMAP_ENTRY* lpEntries;
};
struct AFX_MSGMAP_ENTRY // MFC 4.0 format
{
UINT nMessage; // windows message
UINT nCode; // control code or WM_NOTIFY code
UINT nID; // control ID (or 0 for windows messages)
UINT nLastID; // used for entries specifying a range of control id's
UINT nSig; // signature type (action) or pointer to message #
AFX_PMSG pfn; // routine to call (or special value)
};
基于Docment/View的窗口处理函数创建过程
最终只要是基于CWnd的类都将自己的窗口函数注册为AfxWndProc,注册过程如下
1.CWnd::CreateEx
2. AfxHookWindowCreate
3. AfxHookWindowCreate
4. _AfxCbtFilterHook
5. _AfxStandardSubclass((HWND)wParam)
6. AfxGetAfxWndProc()
7. AfxWndProc
消息流动如下