home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_11 / feeney / timer2.c < prev   
Text File  |  1993-05-21  |  697b  |  29 lines

  1.           LISTING 5
  2.   An Improved WINDOWS Timer Function
  3.  
  4. /*
  5.   Wait until delay has expired,
  6.   but yield control back to WINDOWS
  7.   to let other tasks run.
  8.  
  9.   delay in milliseconds.
  10. */
  11. BOOL Timer( long delay ) {
  12.   MSG  msg;    // Windows message to process.
  13.   long timer,  // current time
  14.        base;   // start time.
  15.  
  16.   if ( !delay || (base=clock()) == -1L ) {
  17.     return(FALSE);  // Return if problems
  18.   }
  19.   delay += base;    // Time at which to exit.
  20.   do {
  21.     while (PeekMessage(&msg,0,0,0, PM_REMOVE)) {
  22.       TranslateMessage(&msg);
  23.       DispatchMessage(&msg);
  24.     }
  25.     if ((timer = clock()) == -1L ) return(FALSE);
  26.   } while ( delay > timer );
  27.   return(TRUE);
  28. }
  29.