突然间想起这个是因为最近看到了AFX_MSGMAP_ENTRY这个结构,结果愣了半天,于是乎干脆又将这一块的相关知识看了一遍,哎,人上了岁数记忆就不行,需要写点东西帮忙记录一下自己的学习历程,不提这个,跑题了:
提起MFC消息,到底程序在哪里处理消息的,因为MFC对windows程序的很多地方进行了封装,导致入口地方不是那么容易找到,不过其实无非就是封装而已——CWinApp(应用程序),在MFC类窗口CxxxApp中查看基类就能找到,调试一下就会发现MFC程序执行的大致流程是:
BOOL AFXAPI AfxInternalPumpMessage()
{
MSG msg;
::GetMessage(&msg, NULL, NULL, NULL);
if (!AfxPreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return TRUE;
}</span></span>
typedef struct tagMSG {
HWND hwnd;
UINT message; //消息的类型(即事件的类型)
WPARAM wParam; //附加或称数据参数1
LPARAM lParam;
DWORD time;
POINT pt;
} MSG; </span>
BEGIN_MESSAGE_MAP(CexampleDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
PTM_WARNING_DISABLE \
const AFX_MSGMAP* theClass::GetMessageMap() const \
{ return GetThisMessageMap(); } \
const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap() \
{ \
typedef theClass ThisClass; \
typedef baseClass TheBaseClass; \
static const AFX_MSGMAP_ENTRY _messageEntries[] = \
{
#define END_MESSAGE_MAP() \
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \
}; \
static const AFX_MSGMAP messageMap = \
{ &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; \
return &messageMap; \
} \
PTM_WARNING_RESTORE
struct AFX_MSGMAP_ENTRY
{
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_PTR nSig; // signature type (action) or pointer to message #
AFX_PMSG pfn; // routine to call (or special value)
};
struct AFX_MSGMAP
{
const AFX_MSGMAP* (PASCAL* pfnGetBaseMap)();
const AFX_MSGMAP_ENTRY* lpEntries;
};
BEGIN_MESSAGE_MAP(CexampleDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()