二级C宏,第1张

二级C宏,第2张

第三,使用C宏自动生成代码的例子很多。不过鉴于很多朋友用的编译器不多,也不做嵌入式开发,我举个win平台的例子。我们知道MFC实现了窗口的消息映射,比如:
on _ command (IDM _ about,on about)
on _ command(IDM _ filenew,on filenew)

它是如何实现IDM_ABOUT和onaut的关联的?它需要几个宏。

# define DECLARE _ MESSAGE _ MAP()\
private:\
static const AFX _ msg MAP _ ENTRY _ MESSAGE entries[];\

protected:\
static AFX _ DATA const AFX _ msg map message map;\
virtual const AFX _ msg map * GetMessageMap()const;\

# define BEGIN _ MESSAGE _ MAP(the class,base class)\
const AFX _ msg MAP * the class::getmessage MAP()const \
{ return & the class::MESSAGE MAP;} \
AFX _ com dat AFX _ DATADEF const AFX _ msg map the class::message map = \
{ & base class::message map,& the class::_ message entries[0]};\
AFX _ com dat const AFX _ msg map _ ENTRY the class::_ message entries[]= \
{ \

#define ON_COMMAND(id,memberFxn) \
{ WM_COMMAND,0,(WORD)id,(WORD)id,AfxSig_vv,(AFX_PMSG)memberFxn },

# define END _ MESSAGE _ MAP()\
{ 0,0,0,0,AfxSig_end,(AFX _ PMSG)0 } \
};\
# define DECLARE _ MESSAGE _ MAP()\
private:\
static const AFX _ msg MAP _ ENTRY _ MESSAGE entries[];\
protected:\
static AFX _ DATA const AFX _ msg map message map;\
virtual const AFX _ msg map * GetMessageMap()const;\

# define BEGIN _ MESSAGE _ MAP(the class,base class)\
const AFX _ msg MAP * the class::getmessage MAP()const \
{ return & the class::MESSAGE MAP;} \
AFX _ com dat AFX _ DATADEF const AFX _ msg map the class::message map = \
{ & base class::message map,& the class::_ message entries[0]};\
AFX _ com dat const AFX _ msg map _ ENTRY the class::_ message entries[]= \
{ \

#define ON_COMMAND(id,memberFxn) \
{ WM_COMMAND,0,(WORD)id,(WORD)id,AfxSig_vv,(AFX_PMSG)memberFxn },

# define END _ MESSAGE _ MAP()\
{ 0,0,0,0,AfxSig_end,(AFX _ PMSG)0 } \
};\


呵呵,就几个宏构造一个消息数组。

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 二级C宏

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情