ACTIVEX DLL时,如何在回调函数中改变DLL的一些私有变量的值,并触发用户事件?

By CSDN  daviddivad   (你真行,居然比我还快! Scorpio)

 请看例子:  
  两个类模块  
  clsTimer:  
  公有类,用于输出  
  clsSendMessage:  
  私有类,用于中转,便于触发公有类的事件  
  一个标准模块  
  modTime:  
  回调函数所在的模块  
   
  原代码:  
   
  clsTimer:  
  Option   Explicit  
  Private   Declare   Function   SetTimer   Lib   "user32"   (ByVal   hwnd   As   Long,   ByVal   nIDEvent   As   Long,   ByVal   uElapse   As   Long,   ByVal   lpTimerFunc   As   Long)   As   Long  
  Private   Declare   Function   KillTimer   Lib   "user32"   (ByVal   hwnd   As   Long,   ByVal   nIDEvent   As   Long)   As   Long  
   
   
  Private   m_lngTimerHandle   As   Long  
  Private   WithEvents   m_oMessage   As   clsSendMessage  
   
   
  Public   Event   Timer()  
   
  Public   Sub   StartTick()  
  m_lngTimerHandle   =   SetTimer(0,   0,   1000,   AddressOf   TimerFunc)  
  End   Sub  
   
  Public   Sub   StopTick()  
  KillTimer   0,   m_lngTimerHandle  
  m_lngTimerHandle   =   0  
  End   Sub  
   
  Private   Sub   Class_Initialize()  
  Set   m_oMessage   =   g_oMessage  
  End   Sub  
   
  Private   Sub   Class_Terminate()  
  KillTimer   0,   m_lngTimerHandle  
  End   Sub  
   
  Private   Sub   m_oMessage_MessageArrval()  
  WriteClick  
  RaiseEvent   Timer  
  End   Sub  
   
  Private   Sub   WriteClick()  
  Debug.Print   "a   tick"  
  End   Sub  
   
  clsSendMessage:  
  Option   Explicit  
   
  Public   Event   MessageArrval()  
   
  Public   Sub   SendMessage()  
  RaiseEvent   MessageArrval  
  End   Sub  
   
  modTime:  
  Option   Explicit  
   
  Public   g_oMessage   As   New   clsSendMessage  
  Public   Sub   TimerFunc(ByVal   hwnd   As   Long,   ByVal   uMsg   As   Long,   ByVal   idEvent   As   Long,   ByVal   dwTime   As   Long)  
  g_oMessage.SendMessage  
  End   Sub  

posted @ 2007-10-16 09:38  彷徨......  阅读(345)  评论(0编辑  收藏  举报