计算机二级C宏智者的利刃,愚者的恶梦-中-

文章作者 100test 发表时间 2007:09:06 13:31:51
来源 100Test.Com百考试题网


  (续上)例三、用c宏,自动生成代码这方面的例子也是多得很,不过有鉴于很多朋友不用很多编译器,不做嵌入式的开发,我就举个win平台的例子吧。我们知道mfc实现了windows的消息映射,比如: on_command(idm_about, onabout)
on_command(idm_filenew, onfilenew)
  它是如何实现的idm_about和onabout的关联的呢?这要用到几个宏。
#define declare_message_map() /
private: /
static const afx_msgmap_entry _messageentries[]. /
protected: /
static afx_data const afx_msgmap messagemap. /
virtual const afx_msgmap* getmessagemap() const. /
#define begin_message_map(theclass, baseclass) /
const afx_msgmap* theclass::getmessagemap() const /
{ return &.theclass::messagemap. } /
afx_comdat afx_datadef const afx_msgmap theclass::messagemap = /
{ &.baseclass::messagemap, &.theclass::_messageentries[0] }. /
afx_comdat const afx_msgmap_entry theclass::_messageentries[] = /
{ /
#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_msgmap_entry _messageentries[]. /
protected: /
static afx_data const afx_msgmap messagemap. /
virtual const afx_msgmap* getmessagemap() const. /
#define begin_message_map(theclass, baseclass) /
const afx_msgmap* theclass::getmessagemap() const /
{ return &.theclass::messagemap. } /
afx_comdat afx_datadef const afx_msgmap theclass::messagemap = /
{ &.baseclass::messagemap, &.theclass::_messageentries[0] }. /
afx_comdat const afx_msgmap_entry theclass::_messageentries[] = /
{ /
#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 } /
}. /

  嘿嘿,就这么几个宏,就构造出一个消息数组来.


相关文章


在VB中调用CHM帮助的几种方法
实例解析VB的事件驱动编程
微软认证考试:70064Windows95考生回顾(2)
计算机二级C宏智者的利刃,愚者的恶梦-下-
计算机二级C宏智者的利刃,愚者的恶梦-中-
计算机二级C宏智者的利刃,愚者的恶梦-上-
国产办公软件W Office2005详细介绍
入门:安装或删除单个Office程序和组件
全国计算机等级考试四级经典词汇荟萃(七)
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛