VB程序中处理随机事件
来源:优易学  2011-1-7 7:16:24   【优易学:中国教育考试门户网】   资料下载   IT书店

  类模块之四:MsgSrv.cls----本模块中定义了消息服务器类MsgServer,该类是消息广播引擎的主体,它主要管理维护消息接收器列表(Clients),将发送来的消息(调用SendMsg过程)依次发送给列表中的所有接收器。注意,这个类被声明为公共全局类,这主要是为了方便使用(不必在每个程序中再建立该类,过程名全局有效)。

Option Explicit

/说 明:

/消 息 服 务 器 类

/发 送 消 息

Public Sub SendMsg(msg As VbMsg)

  Dim c As MsgClient

  For Each c In Clients

    c.SetMsg msg

    DoEvents

  Next c

End Sub

/增 删 消 息 接 收 客 户

Public Sub AddMsgClient(c As MsgClient)

  CliCount = CliCount + 1

  c.Id = CliCount

  Clients.Add c, c.Key

End Sub

Public Sub DelMsgClient(c As MsgClient)

  Clients.Remove c.Key

  If Clients.Count = 0 Then CliCount = 0

End Sub

上一页  [1] [2] [3] [4] 下一页

责任编辑:虫虫

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训