home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pIntui / Clock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  7.1 KB  |  238 lines

  1. #ifndef __INC_POS_PCOM_EXT_CLOCK_C
  2. #define __INC_POS_PCOM_EXT_CLOCK_C
  3. /*******************************************************************
  4.  $CRT 17 Oct 1996 : hp
  5.  
  6.  $AUT Holger Burkarth
  7.  $DAT >>Clock.c<<   29 Jan 1997    13:22:27 - (C) ProDAD
  8. *******************************************************************/
  9.  
  10. //##ex mcpp:cppc -gs -o pos:pos/Ex/Clock p:pLib/StartCode.o p:/pOS_RKRM/pIntui/Clock.c p:pLib/StdIO.o -l pOSStub -l pOS
  11.  
  12. /***********************************************************
  13.   pOS programing example - Copyright (C) 1995-97 proDAD
  14.  
  15.   This code was written as an easy to understand example,
  16.   how to program pOS features. It is provided 'as-is',
  17.   without any express or implied warranty.
  18.  
  19.   Permission is hereby granted to use, copy and modify
  20.   this source code for any purpose, without fee, subject
  21.   to the following conditions:
  22.  
  23.     (1) This notice may not be removed or altered from any
  24.         source distribution.
  25.  
  26.     (2) Altered source versions must be plainly marked as
  27.         such, and must not be misrepresented as being
  28.         the original source code.
  29.  
  30.     (3) If only executable code is distributed, then the
  31.         accompanying documentation have to state that
  32.         "this software is based in part on examples of
  33.         the pOS developer packet".
  34.  
  35.     (4) Permission for use of this code is granted only
  36.         if the user accepts full responsibility for any
  37.         undesirable consequences. proDAD accept NO LIABILITY
  38.         for damages of any kind.
  39.  
  40.   ©proDAD
  41. ***********************************************************/
  42.  
  43. /*\
  44. *** Example:
  45. ***
  46. \*/
  47.  
  48.  
  49. #define __COMPUTER_AMIGA 1
  50. #define NOMYDEBUG
  51.  
  52. #include "p:pExec/Types.h"
  53. #include "p:pDOS/ArgTags.h"
  54. #include "p:pDOS/DosSig.h"
  55. #include "p:pDOS/DosErrors.h"
  56. #include "p:pGadget/Gadget.h"
  57. #include "p:pScreen/ScrTags.h"
  58. #include "p:pScreen/Window.h"
  59. #include "p:pScreen/Screen.h"
  60. #include "p:pIntui/IntuMsg.h"
  61. #include "p:pIntui/Tags.h"
  62. #include "p:pPrefs/PrefsTags.h"
  63. #include "p:proto/pLibExt.h"
  64. #include "p:proto/pExec2.h"
  65. #include "p:proto/pDOS2.h"
  66. #include "p:proto/pIntui2.h"
  67.  
  68. #ifdef _____ME_____
  69.   #include "grund/inc_string.h"
  70.   #include "grund/inc_stdio.h"
  71. #else
  72.  #ifdef __cplusplus
  73.  extern "C" {
  74.  #endif
  75.   #include <string.h>
  76.   #include <stdio.h>
  77.  #ifdef __cplusplus
  78.  }
  79.  #endif
  80. #endif
  81.  
  82.  
  83. const CHAR *HelpText=
  84. ""
  85. ;
  86.  
  87. const CHAR *PrgHeader=
  88. "A little clock";
  89.  
  90. const CHAR *PrgVerText=
  91. "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Papajewski)";
  92.  
  93.  
  94. struct pOS_IntuiDevice *gb_IntuiBase;
  95.  
  96.  
  97. /*----------------------------------
  98. -----------------------------------*/
  99. #ifdef __cplusplus
  100. extern "C"
  101. #endif
  102. VOID main()
  103. {
  104.   struct pOS_DosArgs* Args;
  105.   ULONG Ops[1]={0};
  106.  
  107.   gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  108.  
  109.   /* Allways call pOS_ReadDosArgs(). */
  110.   /* Also if you haven't any arguments. */
  111.   Args=pOS_ReadDosArgs( "", Ops, 1,
  112.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* short programm discription */
  113.     ARGTAG_HelpText,      (ULONG)HelpText,     /* help text */
  114.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* version string */
  115.     TAG_DONE);
  116.  
  117.   if(Args) {
  118.     pOS_Screen *Scr;
  119.  
  120.     if( Scr = pOS_LockPubScreen(NULL)) {
  121.       const struct pOS_DrawInfo *const Dri = Scr->scr_DrawInfo;
  122.             struct pOS_Gadget   *TimeDisp, *Grp;
  123.             struct pOS_Window   *Win;
  124.  
  125.       TimeDisp = (pOS_Gadget*)pOS_NewIObject( NULL,
  126.         "PREFS:Time_Prefs.library/TimeDispGad.class", 0,
  127.         ICLTAG_DrawInfo,        (ULONG)Dri,
  128.         ICLTAG_Gwk,             1,
  129.         PRFTIDSTAG_CurrentTime, TRUE,
  130.         TAG_DONE );
  131.  
  132.       if( TimeDisp ) {
  133.         Grp = (pOS_Gadget*)pOS_NewIObject( NULL,
  134.           Dri->dri_Names[SCRNAM_GGroupClass], 0,
  135.           ICLTAG_DrawInfo,        (ULONG)Dri,
  136.           ICLTAG_AutoDelete,      TRUE,
  137.           GRPGADTAG_BorLeft,      4,
  138.           GRPGADTAG_BorTop,       4,
  139.           GRPGADTAG_BorRight,     4,
  140.           GRPGADTAG_BorBottom,    4,
  141.           GRPGADTAG_AddGadget,    (ULONG)TimeDisp,
  142.           TAG_DONE );
  143.  
  144.         Win = pOS_OpenWindow(
  145.           SCRTAG_Title,   (ULONG)"Clock",
  146.           SCRTAG_Screen,  (ULONG)Scr,
  147.           SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  148.                           WINFLGF_Activate | WINFLGF_CloseGadget |
  149.                           WINFLGF_Dragbar | WINFLGF_SizeGadget |
  150.                           WINFLGF_SizeBBottom,
  151.           SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_StdSysMsg,
  152.           SCRTAG_ZipGadget,       TRUE,
  153.           SCRTAG_AutoSizeGadget,  (ULONG)Grp,
  154.           SCRTAG_AutoAdjust,      TRUE,
  155.           SCRTAG_UnderMouse,      TRUE,
  156.           TAG_DONE );
  157.  
  158.         if( Win ) {
  159.           struct pOS_MsgPort  ReplyPort;
  160.           struct pOS_TimerIO *TimerIO;
  161.  
  162.           pOS_ConstructMsgPort( &ReplyPort );
  163.           if( TimerIO=(pOS_TimerIO*)pOS_CreateIORequest(&ReplyPort,sizeof(pOS_TimerIO))) {
  164.             pOS_OpenDevice("ptimer.device",TIMERUNIT_VBlank,(pOS_IORequest*)TimerIO,0,0);
  165.             if( TimerIO->tio_Error == 0 ) {
  166.               struct pOS_IntuiMessage *Msg;
  167.               BOOL  Run = TRUE;
  168.               ULONG Signal;
  169.               ULONG WinSig = (1L << Win->win_UserPort->mp_SigBit);
  170.               ULONG TimeSig= (1L << ReplyPort.mp_SigBit);
  171.               ULONG SigMask = WinSig | TimeSig | DOSSIGF_CTRL_C;
  172.  
  173.  
  174.               TimerIO->tio_Command=TRCMD_AddRequest;
  175.               TimerIO->tio_Time.tv_Secs=1;
  176.               TimerIO->tio_Time.tv_Micro=0;
  177.               pOS_SendIO((pOS_IORequest*)TimerIO);
  178.  
  179.               while( Run ) {
  180.  
  181.                 Signal = pOS_WaitSignal( SigMask);
  182.  
  183.                 if( Signal & DOSSIGF_CTRL_C ) Run = FALSE;
  184.  
  185.                 if( Signal & TimeSig ) {
  186.                   pOS_WaitIO((pOS_IORequest*)TimerIO);
  187.  
  188.                   TimerIO->tio_Command=TRCMD_AddRequest;
  189.                   TimerIO->tio_Time.tv_Secs=1;
  190.                   TimerIO->tio_Time.tv_Micro=0;
  191.                   pOS_SendIO((pOS_IORequest*)TimerIO);
  192.  
  193.                   pOS_SetGadgetAttrs( Win, TimeDisp,
  194.                     PRFTIDSTAG_CurrentTime, TRUE, TAG_DONE );
  195.                 }
  196.  
  197.                 if( Signal & WinSig ) {
  198.                   while( Msg=(pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  199.  
  200.                     switch( Msg->im_Class ) {
  201.                       case IDCMP_CloseWindow:
  202.                         Run = FALSE;
  203.                         break;
  204.  
  205.                       default:
  206.                         break;
  207.                     }
  208.  
  209.                     if( pOS_SysIMessage(Msg) == FALSE )
  210.                       pOS_ReplyMsg( (pOS_Message*)Msg );
  211.                   }
  212.                 }
  213.               }
  214.               pOS_AbortIO((pOS_IORequest*)TimerIO);
  215.               pOS_WaitIO((pOS_IORequest*)TimerIO);
  216.  
  217.               pOS_CloseDevice((pOS_IORequest*)TimerIO);
  218.             }
  219.             else printf("Cannot open ptimer.device.\n");
  220.             pOS_DeleteIORequest((pOS_IORequest*)TimerIO);
  221.           }
  222.           pOS_DestructMsgPort( &ReplyPort );
  223.           pOS_CloseWindow( Win );
  224.         }
  225.         else printf("Cannot open TimeDispGad.\n");
  226.       }
  227.       else printf("Cannot open window.\n");
  228.       pOS_UnlockPubScreen( Scr );
  229.     }
  230.     else printf("Cannot lock public screen.\n");
  231.     pOS_DeleteDosArgs( Args );
  232.   }
  233.  
  234.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  235. }
  236.  
  237. #endif
  238.