读书人

MFC函数指针来指教多谢

发布时间: 2012-03-16 16:34:56 作者: rapoo

MFC函数指针,高手进来指教,谢谢
小弟近日学MFC,遇到下面一个宏,不明白,请高手讲解:
#define ON_NOTIFY(wNotifyCode, id, memberFxn) \
{ WM_NOTIFY, (WORD)(int)wNotifyCode, (WORD)id, (WORD)id, AfxSig_vNMHDRpl, \
(AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))&memberFxn },


1。这一句:(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))定义了一个函数指针偶能看明白,但(AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))这样是什么意思呢?--(AFX_PMSG)转型?为什么要转型?
2。(AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))&memberFxn这一整句话呢?



[解决办法]
看看 AFX_PMSG 宏的定义
[解决办法]
(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))&memberFxn

这个是将 &memberFxn 强制转换为 CCmdTarget的成员函数指针,
前面的 AFX_PMSG 好像是和 消息映射相关联的 ~~
[解决办法]
语法上不难理解,就是要解开MFC是一件困难的事情.

< <MFC深入浅出> > 里面帮你解开这些 "精美 "的宏.
[解决办法]
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)
};
首先转化为类的成员函数(可以在编译期发现问题,即memberFxn是否是真的成员函数),然后统一转化为AFX_PMSG函数指针(方便post消息到具体的窗口)

[解决办法]
是的
[解决办法]
学习中。。。。

读书人网 >C++

热点推荐