home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / c / cwl30 / cwl3demo / clocdemo.c next >
Encoding:
C/C++ Source or Header  |  1994-10-06  |  1.9 KB  |  92 lines

  1. #include "cwlwin.h"
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define NORM  CREATE_VIDEO_ATTRIBUTE(BLACK_ ,WHITE_)
  7. #define COLOR1 CREATE_VIDEO_ATTRIBUTE(WHITE_ ,BLACK_)
  8.  
  9. WPOINTER clock_win, wtop;
  10. FILE *clockfile;
  11.  
  12. int do_clock(WPOINTER,int,int,long);
  13.  
  14. /*DoClock() {}*/
  15.  
  16.  
  17. #ifdef MAINPROG
  18. void main( )
  19. #else
  20. CWL_VOID DoClock( )
  21. #endif
  22. {
  23. #ifndef SHWARE
  24.   int b;
  25.   clock_win = WindowInitialize(DESKTOP_WINDOW,BORDER,0,0,60,3,COLOR1,
  26.                                COLOR1,SINGLEBOX);
  27.   WindowCenter(clock_win,VERTCENTER | HORIZCENTER);
  28.   WindowChangeCursor(clock_win,INVISIBLE);
  29.   WindowDisplay(clock_win,1,NOEFFECT);
  30.  
  31.   WindowSetEventStyle(clock_win,CWL_CAPTION | CWL_RESIZE);
  32.   WindowSetCaption(clock_win,"Real Time Clock Demo");
  33.   WindowSetEventProc(clock_win,do_clock);
  34.   SetWinTimer(clock_win,1,1000,(TIMERPROC)0);
  35.   WindowSetFocus(clock_win); /* Set the focus for the clock window */
  36.   WindowWriteCenterString(clock_win,"Press Space Bar to Quit",1);
  37.   clockfile = fopen("CLOCK.OUT","w");
  38.   /* Initialize Event System */
  39.   ProcessAllEvents(M_EVENT | K_EVENT | T_EVENT);
  40.   WindowClose(clock_win,NOEFFECT);
  41.   fclose(clockfile);
  42. #else
  43.   NotAvailable( );
  44. #endif
  45. }
  46.  
  47.  
  48.  
  49. int do_clock(WPOINTER w, int message, int wParam, long lParam)
  50. {
  51. #ifndef SHWARE
  52.   time_t t;
  53.   static int timeon = FALSE;
  54.   char buf[100];
  55.  
  56.   switch (message)
  57.   {
  58.     case CWL_TIMER:
  59.     {
  60.       if (!timeon)
  61.       {
  62.         timeon = TRUE;
  63.         time(&t);
  64.         sprintf(buf,"Current Date and Time is: %s",ctime(&t));
  65.         WindowWriteCenterString(w,strtok(buf,"\n"),0);
  66.         fprintf(clockfile,buf);
  67.         timeon = FALSE;
  68.       }
  69.     }
  70.     break;
  71.  
  72.     case CWL_SIZE:
  73.     {
  74.       WindowWriteCenterString(w,"Press Space Bar to Quit",1);
  75.     }
  76.     break;
  77.  
  78.     case CWL_CHAR:
  79.      if (wParam == ' ')
  80.      {
  81.        CWLQuitMessage();
  82.      }
  83.     break;
  84.  
  85.   }
  86.   return FALSE;
  87. #else
  88.   return 0;
  89. #endif
  90. }
  91.  
  92.