| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 815 人关注过本帖
标题:自定义dos消息响应
只看楼主 加入收藏
maomsx
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-19
收藏
 问题点数:0 回复次数:1 
自定义dos消息响应
#ifndef __DISPATCH_HPP
#define __DISPATCH_HPP

#ifndef  BOOL
typedef  int  BOOL;  //定义布尔类型及两个布尔常量:
#endif
#ifndef TRUE
#define TRUE  1
#endif
#ifndef FALSE
#define FALSE 0
#endif
class     GENERIC;         //通用抽象类定义
typedef   void  (GENERIC::*TAnyPMF)();    //类成员函数指针类型

typedef   int (*TAnyDispatcher)(GENERIC&, TAnyPMF, int,int);

template  <class T>  class  TResponseTableEntry { //消息事件响应表子项
  public:

    typedef   void  (T::*PMF)();

    int NotifyCode;  // 消息通知码
    int bSyntax;     // 语法检查(==TRUE)或语义检查(==FALSE)标志
    TAnyDispatcher Dispatcher;  //消息派遣函数指针
    PMF pmf;   //消息事件响应函数(类成员函数)指针
};

typedef    TResponseTableEntry<GENERIC>    TGenericTableEntry; //通用消息响应表类型

class   TEventInfo {//消息事件定义
    public:
            const  int NotifyCode;  //消息值
            const  BOOL bSyntax;   //语法检查(==TRUE)或语义检查(==FALSE)标志
            const  int iPara; //菜单消息携带的参数
            GENERIC *Object;   //接收该消息的对象
            TGenericTableEntry  *Entry;  //对象的消息事件响应表
            TEventInfo(int aNotifyCode=-1,int syntax=1,int Para=0) :
                        NotifyCode(aNotifyCode),bSyntax(syntax),iPara(Para)  // 构造器:
                        {   Entry=0;  }
};

class   TEventHandler {  //消息事件管理器
  public:
     //    消息事件表搜索函数. 由于TEventHandler没有任何消息响应表,
     //本函数不做任何动作,仅返回FALSE.
     //    所有与消息事件表处理有关的对象类必须是TEventHandler的子类,
     //且必须重载该函数.
     virtual   BOOL   Find(TEventInfo& info);

     //    从TEventInfo类型的消息事件数据中取出消息数据,并把它派遣
     //给相应的响应函数.
     virtual  int  Dispatch(TEventInfo& info);

 protected:
     //搜索消息事件表entries, 看其中是否含有有关info消息事件的项:
     BOOL  SearchEntries(TGenericTableEntry *entries, TEventInfo &info);
};

#define DECLARE_RESPONSE_TABLE(cls)   /*声明消息事件响应表*/   \
    private:                                                    \
         /*   定义消息事件响应表变量,使其为静态变量,以便被*/     \
         /* 该类的所有对象共享                            */     \
      static   TResponseTableEntry<cls>  __entries[];           \
         /*   类成员函数指针定义:                         */     \
      typedef   TResponseTableEntry<cls>::PMF  TMyPMF;          \
         /*   类名记忆:                                   */     \
      typedef   cls  TMyClass;                                  \
    public: /* 重载搜索函数定义:                         */     \
      BOOL   Find(TEventInfo&);

#define DEFINE_RESPONSE_TABLE_ENTRIES(cls)                 \
              TResponseTableEntry<cls>  cls::__entries[] = {

#define   DEFINE_RESPONSE_TABLE1(cls, base1) /* 定义响应表 */      \
    /* 重载搜索响应表函数:                                  */      \
  BOOL   cls::Find(TEventInfo& eventInfo) {                        \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/         \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                            || base1::Find(eventInfo);                    \
    }                                                               \
  /* 定义响应表的内容:                                     */      \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

#define   DEFINE_RESPONSE_TABLE2(cls, base1, base2) /* 定义响应表 */ \
    /* 重载搜索响应表函数:                                  */        \
  BOOL   cls::Find(TEventInfo& eventInfo) {                          \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/           \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                || base1::Find(eventInfo) || base2::Find(eventInfo);     \
    }                                                                 \
  /* 定义响应表的内容:                                     */        \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

#define   DEFINE_RESPONSE_TABLE3(cls, base1, base2, base3) /* 定义响应表 */ \
    /* 重载搜索响应表函数:                                  */        \
  BOOL   cls::Find(TEventInfo& eventInfo) {                          \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/           \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                || base1::Find(eventInfo) || base2::Find(eventInfo) || base3::Find(eventInfo);     \
    }                                                                 \
  /* 定义响应表的内容:                                     */        \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

#define   DEFINE_RESPONSE_TABLE4(cls, base1, base2, base3, base4) /* 定义响应表 */ \
    /* 重载搜索响应表函数:                                  */        \
  BOOL   cls::Find(TEventInfo& eventInfo) {                          \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/           \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                || base1::Find(eventInfo) || base2::Find(eventInfo)\
                || base3::Find(eventInfo) || base4::Find(eventInfo);     \
    }                                                                 \
  /* 定义响应表的内容:                                     */        \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

#define   DEFINE_RESPONSE_TABLE5(cls, base1, base2, base3, base4, base5) /* 定义响应表 */ \
    /* 重载搜索响应表函数:                                  */        \
  BOOL   cls::Find(TEventInfo& eventInfo) {                          \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/           \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                || base1::Find(eventInfo) || base2::Find(eventInfo)\
                || base3::Find(eventInfo) || base4::Find(eventInfo);     \
                || base5::Find(eventInfo);     \
    }                                                                 \
  /* 定义响应表的内容:                                     */        \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

#define   DEFINE_RESPONSE_TABLE6(cls, base1, base2, base3, base4, base5, base6) /* 定义响应表 */ \
    /* 重载搜索响应表函数:                                  */        \
  BOOL   cls::Find(TEventInfo& eventInfo) {                          \
              eventInfo.Object = (GENERIC*)this; /*当前对象*/           \
              return  SearchEntries((TGenericTableEntry *) __entries,eventInfo)\
                || base1::Find(eventInfo) || base2::Find(eventInfo)\
                || base3::Find(eventInfo) || base4::Find(eventInfo);     \
                || base5::Find(eventInfo) || base6::Find(eventInfo);     \
    }                                                                 \
  /* 定义响应表的内容:                                     */        \
  DEFINE_RESPONSE_TABLE_ENTRIES(cls)

//我们以零结束对响应表的定义:
#define    END_RESPONSE_TABLE          {   0,    0,   0,   0 }  }

//语法和语义检查标志:
#define SYNTAX    1
#define SEMANTICS 0

// 消息响应表宏定义:
#define  EvGxxSyntax(F_Gxx,Gxx)  { F_Gxx, SYNTAX, \
                            (TAnyDispatcher)::DispatchGCodeSyntax, (TMyPMF)Gxx}
#define  EvGxxSemantics(F_Gxx,Gxx)  { F_Gxx, SEMANTICS,\
                            (TAnyDispatcher)::DispatchGCodeSemantics, (TMyPMF)Gxx}
#define  EvGxx(F_Gxx,Gxx)  EvGxxSyntax(F_Gxx,Gxx), \
                                    EvGxxSemantics(F_Gxx,Gxx)
#define  EvMenu(MENU_MSG,MT) { MENU_MSG, 0,\
                (TAnyDispatcher)::DispatchMenuMessage, (TMyPMF)MT}


// 菜单消息派遣器
extern int DispatchMenuMessage(GENERIC &Object,int (GENERIC::*pmf)(int), BOOL,int para=0);

#endif
搜索更多相关主题的帖子: dos 定义 
2008-04-21 22:54
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
回复 1# 的帖子
什么编译器的 ?怎么DOS 也支持函数模板?
2008-04-25 10:33
快速回复:自定义dos消息响应
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064725 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved