home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / TIMER.PRG < prev    next >
Text File  |  1994-04-16  |  1KB  |  63 lines

  1. #include "FiveWin.ch"
  2.  
  3. static aTimers := {}
  4. static nId     := 1
  5.  
  6. //----------------------------------------------------------------------------//
  7.  
  8. CLASS TTimer
  9.  
  10.    DATA   bAction
  11.    DATA   lActive
  12.    DATA   nId, nInterval
  13.    DATA   hWndOwner
  14.  
  15.    METHOD New( nInterval, bAction, oWnd ) CONSTRUCTOR
  16.  
  17.    METHOD Activate()
  18.  
  19.    METHOD DeActivate() INLINE ::lActive := .f., KillTimer( ::hWndOwner, ::nId )
  20.  
  21.    METHOD Release() INLINE ::DeActivate(), Self := nil
  22.  
  23. ENDCLASS
  24.  
  25. //----------------------------------------------------------------------------//
  26.  
  27. METHOD New( nInterval, bAction, oWnd ) CLASS TTimer
  28.  
  29.    DEFAULT nInterval := 18, bAction := { || nil }
  30.  
  31.    ::nInterval = nInterval
  32.    ::bAction   = bAction
  33.    ::nId       = nId++
  34.    ::lActive   = .f.
  35.    ::hWndOwner = If( oWnd != nil, oWnd:hWnd, GetActiveWindow() )
  36.  
  37.    AAdd( aTimers, Self )
  38.  
  39. return
  40.  
  41. //----------------------------------------------------------------------------//
  42.  
  43. METHOD Activate() CLASS TTimer
  44.  
  45.    ::nId     = SetTimer( ::hWndOwner, ::nId, ::nInterval, 0 )
  46.    ::lActive = .t.
  47.  
  48. return
  49.  
  50. //----------------------------------------------------------------------------//
  51.  
  52. function TimerEvent( nId )
  53.  
  54.    local nTimer := AScan( aTimers, { | oTimer | oTimer:nId == nId } )
  55.  
  56.    if nTimer != 0
  57.       Eval( aTimers[ nTimer ]:bAction )
  58.    endif
  59.  
  60. return 0
  61.  
  62. //----------------------------------------------------------------------------//
  63.