home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / BARCLOCK.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  2KB  |  64 lines

  1. @echo off
  2. REM *****************************************************************
  3. REM *** BarClock.cmd - CEnvi2 for OS/2 utility to show the current ***
  4. REM *** ver.2          time in the title bar of the currently     ***
  5. REM ***                active window.                             ***
  6. REM *****************************************************************
  7.  
  8. START "BarClock Forever" /N CEnvi2.exe BarClock.cmd
  9. GOTO CENVI_EXIT
  10.  
  11. #define UPDATE_FREQUENCY   1000 // milliseconds between update
  12.  
  13. // Adjust strftime statement to get your own version of time.
  14. // Uncomment the one you want
  15. //TimeFormat = "%I:%M%p";  // 12-hour and minute and AM or PM
  16. //TimeFormat = "%H:%M:%S"; // 24-hour hour:minute:second
  17. TimeFormat = "%I:%M:%S";   // 12-hour hour:minute:second
  18.  
  19. #include <WinTools.lib>
  20.  
  21. // hide this window
  22. ShowWindow(Info().WinHandle,SW_HIDE);
  23.  
  24. TimeWindow = NULL;
  25.  
  26. while( True ) {
  27.    suspend(UPDATE_FREQUENCY);
  28.    Hwnd = GetActiveWindow();
  29.    if ( Hwnd != TimeWindow ) {
  30.       // New window, so remove time from old window title
  31.       if ( TimeWindow ) {
  32.          if ( Title = GetWindowTitle(TimeWindow) ) {
  33.             RemoveTimeFromTitle(Title);
  34.             SetWindowTitle(TimeWindow,Title);
  35.          }
  36.       }
  37.    }
  38.    if ( TimeWindow = Hwnd ) {
  39.       // Add time to this window
  40.       if ( Title = GetWindowTitle(TimeWindow) ) {
  41.          RemoveTimeFromTitle(Title);
  42.          SetWindowTitle(TimeWindow,AddTimeToTitle(Title));
  43.       }
  44.    }
  45. }
  46.  
  47.  
  48. #define TIME_SEQUENCE   '\xFF-\xFF'
  49.  
  50. AddTimeToTitle(pTitle)
  51. {
  52.    strftime(lTime,TimeFormat,localtime(time()));
  53.    sprintf(lTitle,"%s%s%s",pTitle,TIME_SEQUENCE,lTime);
  54.    return lTitle;
  55. }
  56.  
  57. RemoveTimeFromTitle(pTitle)
  58. {
  59.    if ( lSequence = strstr(pTitle,TIME_SEQUENCE) )
  60.       lSequence[0] = '\0';
  61. }
  62.  
  63. :CENVI_EXIT
  64.