用MFC的ClassWizard创建的工程,MFC利用几个宏建立了一个消息映射网,把一个消息处理函数和一个ID捆绑起来。至于消息映射网的建立,在侯先生的<深入浅出MFC>中已经解释的很清楚了,在此不说。在看书的时候有一个问题当时没有想明白,它是怎么把一个类的成员函数赋值给一个函数指针的?还有对于带有不同参数类型的成员函数,它是怎么用一个函数指针给统一赋值的?
现在看一下在类头文件中用到一个宏是怎么定义的(AFXWIN.H)
#define DECLARE_MESSAGE_MAP() /
private: /
static const AFX_MSGMAP_ENTRY _messageEntries[]; /
protected: /
static AFX_DATA const AFX_MSGMAP messageMap; /
static const AFX_MSGMAP* PASCAL _GetBaseMessageMap(); /
virtual const AFX_MSGMAP* GetMessageMap() const; /
其中重要的一个AFX_MSGMAP_ENTRY的定义是(AFXWIN.H)
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 nSig; // signature type (action) or pointer to message