home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / bigben2.zip / bigben2.cc < prev    next >
Text File  |  1993-12-15  |  7KB  |  229 lines

  1. //////////////////////////////////////////////
  2. // bigben2.cc -- bigben Version 2 (for MMPM)
  3. //
  4. // This plays the bigben tune every hour
  5. //
  6. //
  7. // Marc E.E. van Woerkom, 13.12.93     [MvW]
  8. //
  9.  
  10.  
  11. #define OS2EMX_PLAIN_CHAR
  12.  
  13. #define INCL_DOSPROCESS   // DosBeep()
  14. #define INCL_DOSDATETIME  // DosGetDateTime()
  15. #define INCL_WIN
  16. #define INCL_REXXSAA      // use REXX interpreter
  17.  
  18. #include <os2.h>
  19.  
  20.  
  21. //
  22. // call REXX procedure "dingdong.cmd"
  23. //
  24.  
  25. void dingdong()
  26. {
  27.     LONG ReturnCode;
  28.  
  29.     char Resultbuf[80];
  30.     RXSTRING Result;
  31.     MAKERXSTRING(Result, Resultbuf, 80);  // initialize RXSTRING
  32.  
  33.     RexxStart(0,
  34.               0,
  35.               "dingdong",
  36.               0,
  37.               0,
  38.               RXCOMMAND,
  39.               0,
  40.               (SHORT*)&ReturnCode,  // cast due to incorrect emx header
  41.               &Result);
  42. }
  43.  
  44.  
  45. const ULONG ID_TIMER = 1;
  46.  
  47. HAB  hab;
  48. HWND hwndClient;
  49.  
  50. int  first_sync;
  51. int  sync;
  52. int  min_event;
  53. int  sec_event;
  54.  
  55.  
  56. //
  57. // PM client window procedure
  58. //
  59.  
  60. extern "C"
  61. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  62. {
  63.     switch (msg) {
  64.  
  65.     case WM_CREATE:         // tunes shamelessly cloned from Petzold :-)
  66.         DosBeep(261, 100);
  67.         DosBeep(330, 100);
  68.         DosBeep(392, 100);
  69.         DosBeep(523, 500);
  70.         return 0;
  71.  
  72.  
  73.     // Use minute ticks except at start and at hh.59.ss
  74.  
  75.     case WM_TIMER:
  76.         DATETIME DateTime;                     // get the time
  77.         DosGetDateTime(&DateTime);
  78.  
  79.         if (first_sync) {                      // get into sync with full minutes
  80.             // DosBeep(5000, 50);
  81.  
  82.             if (DateTime.seconds == 0) {
  83.                 first_sync = 0;                // at hh.mm.00 -> first sync performed
  84.                 sec_event = 0;
  85.  
  86.                 if (DateTime.minutes == 59) {  // at hh.59.00 -> 1s steps
  87.                     sync = 1;
  88.                     min_event = 59;
  89.                 }
  90.                 else { 
  91.                     sync = 0;                  // slow down
  92.                     WinStartTimer(hab,         // input anchor block
  93.                                   hwndClient,  // input window handle
  94.                                   ID_TIMER,    // timer id
  95.                                   60000);      // intervall in milliseconds
  96.  
  97.                     if (DateTime.minutes == 0) // if started later than hh.59.00
  98.                         dingdong();
  99.                 }
  100.             }
  101.         }
  102.         else {
  103.             if (sync) {                        // sync is on (at hh.59.00)
  104.                 // DosBeep(3000, 50);
  105.                 sec_event++;                   // count second steps
  106.  
  107.                 if (sec_event >= 59) {         // ok, now slow down (at hh.59.59)
  108.                     sync = 0;                  // sync off
  109.                     WinStartTimer(hab,         // input anchor block
  110.                                   hwndClient,  // input window handle
  111.                                   ID_TIMER,    // timer id
  112.                                   60000);      // intervall in milliseconds
  113.                     dingdong();
  114.                 }
  115.             }
  116.             else {                             // sync is off (at hh.00.00 ... hh.58.00)
  117.                 // DosBeep(400, 100);
  118.                 min_event = DateTime.minutes;
  119.  
  120.                 if (min_event >= 59) {         // accelerate to second steps
  121.                     sync = 1;                  // sync again
  122.                     sec_event = DateTime.seconds;
  123.  
  124.                     WinStartTimer(hab,         // input anchor block
  125.                                   hwndClient,  // input window handle
  126.                                   ID_TIMER,    // timer id
  127.                                   1000);       // intervall in milliseconds
  128.                 }
  129.             }
  130.         }
  131.  
  132.         return 0;
  133.  
  134.     case WM_DESTROY:        // thanks again, Charles!
  135.         DosBeep(523, 100);
  136.         DosBeep(392, 100);
  137.         DosBeep(330, 100);
  138.         DosBeep(261, 500);
  139.         return 0;
  140.     }
  141.  
  142.     return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  143. }
  144.  
  145.  
  146. //
  147. // main function
  148. //
  149.  
  150. main()
  151. {
  152.     hab = WinInitialize(0);                   // handle: anchor block
  153.  
  154.     HMQ hmq = WinCreateMsgQueue(hab, 0);      // handle: message queue
  155.  
  156.  
  157.     // register ClientWndProc
  158.  
  159.     CHAR ClientClass[] = "bigben2";
  160.  
  161.     WinRegisterClass(hab,           
  162.                      ClientClass,    // name of class being registered
  163.                      ClientWndProc,  // window procedure for class
  164.                      0,              // class style
  165.                      0);             // extra memory to reserve
  166.     
  167.  
  168.     // create parent window
  169.  
  170.     ULONG FrameFlags = FCF_TASKLIST;  // show up in tasklist
  171.  
  172.     HWND hwndFrame = WinCreateStdWindow(HWND_DESKTOP,  // parent
  173.                                         0,             // style
  174.                                         &FrameFlags,   // control data
  175.                                         ClientClass,   // client name
  176.                                         "Burp :-)",    // title bar text
  177.                                         0,             // client style
  178.                                         0,             // resource handle
  179.                                         0,             // resource id
  180.                                         &hwndClient);  // client pointer
  181.  
  182.     // quit if no timer is available
  183.  
  184.     if (WinQuerySysValue(HWND_DESKTOP, SV_CTIMERS) == 0) {
  185.  
  186.         WinMessageBox(HWND_DESKTOP,                                        // parent handle
  187.                       hwndClient,                                          // owner handle
  188.                       "No more timer available.\nCan't continue. Sorry.",  // message
  189.                       "bigben2",                                           // title
  190.                       0,
  191.                       MB_OK |                                              // OK button
  192.                       MB_ICONEXCLAMATION);                                 // "!" icon
  193.     }
  194.     else {
  195.  
  196.         // start timer
  197.  
  198.         first_sync = 1;  // start in 1s steps to synchronize to full minutes
  199.  
  200.         WinStartTimer(hab,         // input anchor block
  201.                       hwndClient,  // input window handle
  202.                       ID_TIMER,    // timer id
  203.                       1000);       // intervall in milliseconds
  204.  
  205.  
  206.         // it's not a trick, it's a message loop!
  207.  
  208.         QMSG qmsg;  // queue: message queue
  209.  
  210.         while(WinGetMsg(hab, &qmsg, 0, 0, 0))
  211.             WinDispatchMsg(hab, &qmsg);
  212.  
  213.  
  214.         // stop timer
  215.  
  216.         WinStopTimer(hab,         // input anchor block
  217.                      hwndClient,  // input window handle
  218.                      ID_TIMER);   // timer id
  219.     }
  220.  
  221.  
  222.     WinDestroyWindow(hwndFrame);  // kill window
  223.     WinDestroyMsgQueue(hmq);      // kill message queue
  224.     WinTerminate(hab);            // that's all!
  225.  
  226.     return 0;
  227. }
  228.  
  229.