計算機二級C宏智者的利刃,愚者的惡夢

計算機二級C宏智者的利刃,愚者的惡夢,第1張

計算機二級C宏智者的利刃,愚者的惡夢,第2張

(續)例3。使用C宏自動生成代碼的例子有很多。不過,由於很多朋友用的編譯器不多,也不做嵌入式開發,所以我擧個win平台的例子。我們知道mfc實現了窗口的消息映射,比如:on _ command (idm_about,onabout)
on _ command(IDM _ filenew,on filenew)
它是如何實現idm_about和on about之間的關聯的?它需要幾個宏。
# 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/
# 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/

呵呵,就幾個宏搆造一個消息數組。

位律師廻複

生活常識_百科知識_各類知識大全»計算機二級C宏智者的利刃,愚者的惡夢

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情