home *** CD-ROM | disk | FTP | other *** search
/ Spanish Scene 4 / SpanishScene4.iso / Programas / DavidBarbion_Ind / backclock_V232c.lha / BackClock / sources / main.c < prev    next >
C/C++ Source or Header  |  1999-06-12  |  3KB  |  108 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom      : main.c
  4.  *
  5.  * version    : $VER: main.c 1.2 (12.06.99)
  6.  *
  7.  * History of backclock
  8.  * V1.0: initial version
  9.  * V1.1: can be started from WB with Tooltypes
  10.  *       added notifyintuition routines to close the window automatically
  11.  * v1.2: window can initialy sized thanks to tooltypes
  12.  *       window goes to back every seconds
  13.  *       first public release
  14.  * v1.3: close|open workbench now works
  15.  *       changed clock style
  16.  * v2.0: Totally customizable via a GUI (no tooltypes anymore)
  17.  * v2.1: Transparent. Removed some unused code 
  18.  * v2.32b: redraw window when (de)selected 
  19.  *         uses rtracker.library
  20.  * v2.32c: now stay in front of Workbench or Directory Opus
  21.  *         last minute : now set task priority to -20
  22.  *
  23.  * future: customizable clock style
  24.  *
  25.  *****************************************************************************
  26.  */
  27. #include <intuition/intuition.h>
  28. #include <dos/dos.h>
  29. #include <exec/ports.h>
  30. #include <exec/libraries.h>
  31. #include <exec/memory.h>
  32. #include <workbench/startup.h>
  33.  
  34. #include <proto/intuition.h>
  35. #include <proto/exec.h>
  36. #include <proto/dos.h>
  37. #include "utils.h"
  38. /* bump revision
  39.  */
  40. char  * nosense = "\0$VER: " TITLE " (12.06.99)" ;
  41.  
  42. void main() {
  43.   /* lance du CLI
  44.    */
  45.   idWin * myprj ;
  46.   if (exists() == FALSE) {
  47.     SetTaskPri(FindTask(NULL), -20) ; // for those who don't use executive
  48.     Delay(50) ;                       // wait 1s on startup
  49.     if ((myprj = init(NULL)) != NULL) {
  50.       //writeDate(myprj) ;
  51.       processwin(myprj) ;
  52.       close(myprj) ;
  53.     }
  54.     
  55.   }
  56.  
  57. }
  58. void wbmain() {
  59.   /* lance du WB
  60.    */
  61.   void main() ;
  62.   main() ;  
  63. }
  64. int exists() {
  65.   /* backclock already launched
  66.    */
  67.   int ret = FALSE ;
  68.   struct EasyStruct EZ ;
  69.   struct MsgPort * oldPort ;
  70.   struct MsgPort * replyPort ; 
  71.   struct backMsg * msg ;
  72.  
  73.   Forbid() ;
  74.   oldPort = FindPort("backclock") ;
  75.   Permit() ;
  76.   
  77.   if (oldPort) {
  78.     /* le programme est deja lance
  79.      */
  80.     EZ.es_StructSize   = sizeof(struct EasyStruct) ;
  81.     EZ.es_Flags        = NULL ;
  82.     EZ.es_Title        = TITLE ;
  83.     EZ.es_TextFormat   = "You are about to quit BackClock\nAre you sure ?" ;
  84.     EZ.es_GadgetFormat = "Quit|Cancel" ;
  85.     if (EasyRequestArgs(NULL, &EZ, NULL, NULL) == 1) {
  86.       /* utilisateur choisit quit
  87.        */  
  88.       if ((replyPort = CreateMsgPort()) != NULL) {
  89.         if ((msg = AllocVec(sizeof(struct backMsg), MEMF_PUBLIC)) != NULL) {
  90.           msg->execmsg.mn_Node.ln_Type = NT_MESSAGE ;
  91.           msg->execmsg.mn_Length       = sizeof(struct backMsg) ;
  92.           msg->execmsg.mn_ReplyPort    = replyPort ;
  93.           msg->Class = BC_Quit ;  // stop !!!
  94.           PutMsg(oldPort, (struct Message*)msg) ;
  95.           WaitPort(replyPort) ;
  96.           DeleteMsgPort(replyPort) ;
  97.           FreeVec(msg) ;
  98.           ret=OK ;
  99.         }else {
  100.           ret=ERRORNOMEM ;
  101.           DeleteMsgPort(replyPort) ;
  102.         }
  103.       }else ret=ERRORNOMEM ;
  104.     }else ret = OK ;
  105.   }
  106.   return(ret) ;
  107. }
  108.