home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vtimer.cpp < prev    next >
C/C++ Source or Header  |  1999-02-21  |  3KB  |  99 lines

  1. //===============================================================
  2. // vTimer.cxx - vTimer class functions - Windows
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>            // for OS/2 stuff
  12. #include <v/vapp.h>
  13. #include <v/vtimer.h>
  14. #include <v/vthislst.h>
  15.  
  16. // Define static data of the class
  17.   MRESULT EXPENTRY vTimerProc(HWND hwnd, UINT msg, UINT idTimer, ULONG mp2);
  18.   extern vThisList _timers;
  19.  
  20. //=========================>>> vTimer::tick <<<=======================
  21.   MRESULT EXPENTRY vTimerProc(HWND hwnd, UINT msg, UINT idTimer, ULONG mp2)
  22.   {
  23.     vTimer* mytime = (vTimer*) _timers.GetThis((ThisId)idTimer);
  24.     if (mytime)                        // Make sure we got a this
  25.       mytime->tick();
  26.     else
  27.     {
  28.       return WinDefWindowProc(hwnd, msg, (VOID*) idTimer, (VOID*) mp2);
  29.     }
  30.     return (MRESULT) mytime;
  31.   }
  32.  
  33. //======================>>> vTimer::vTimer <<<=======================
  34.   vTimer::vTimer( )            // default constructor
  35.   {
  36.     SysDebug(Constructor,"vTimer::vTimer - constructor\n");
  37.     _id = 0;                   // no id
  38.     _interval = 0;             // no interval
  39. //    SysDebug2(OS2Dev,"vTimer:vTimer  this=%x &_timers=%x \n", this, &_timers)
  40.   }
  41.  
  42. //======================>>> vTimer::~vTimer <<<=======================
  43.   vTimer::~vTimer( )
  44.   {
  45.     SysDebug(Destructor,"vTimer::~vTimer - destructor\n");
  46.     if (_id)                   // remove timer if in effect
  47.     {
  48.       TimerStop();
  49.     }
  50.   }
  51.  
  52. //======================>>> vTimer::TimerSet <<<=======================
  53.   int vTimer::TimerSet(long interval)
  54.   {
  55.     if (_id)                   // remove timer if in effect
  56.     {
  57.       TimerStop();
  58.     }
  59.     _interval = interval;
  60.     _id = WinStartTimer(theApp->_hab, NULLHANDLE, 0, _interval);
  61.  
  62.     if (_id != 0)
  63.     {
  64. //      SysDebug3(OS2Dev,"vTimer:TimerSet mytime=%x _id=%x _interval=%u \n", this, _id, _interval)
  65. //      SysDebug1(OS2Dev,"   &_timers=%x \n", &_timers)
  66.       _timers.Add((ThisId)_id, (void*)this);
  67.       return 1;
  68.     }
  69.     else
  70.       return 0;
  71.   }
  72.  
  73. //======================>>> vTimer::TimerStop <<<=======================
  74.   void vTimer::TimerStop(void)
  75.   {
  76.     if (_id)                   // remove timer if in effect
  77.     {
  78.  
  79.       WinStopTimer (theApp->_hab, NULLHANDLE, (ThisId)_id);
  80.       _timers.Delete((ThisId)_id);     // delete old timer
  81.       _id = 0;
  82.     }
  83.   }
  84.  
  85. //======================>>> vTimer::TimerTick <<<=======================
  86.   void vTimer::TimerTick(void)
  87.   {
  88.     // default has no action - will be overridden
  89.   }
  90.  
  91. //=========================>>> vTimer::tick <<<=======================
  92.   void vTimer::tick(void)
  93.   {
  94.     // internal tick routine
  95.     TimerTick();               // call the work routine
  96.   }
  97.  
  98.  
  99.