home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / easyintuition37.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  5.9 KB  |  161 lines

  1. /* This example shows a simple Intuition program that works with
  2.  * Release 2 (V36) and later versions of the Amiga operating system.
  3.  */
  4.  
  5. /* easyintuition37.c -- Simple Intuition program for V37   */
  6. /* (Release 2) and later versions of the operating system. */
  7. /* Compiled with Lattice C v5.04: lc -L easyintuition37.c  */
  8.  
  9. #include <exec/types.h>             /* The Amiga data types file.         */
  10. #include <intuition/intuition.h>    /* Intuition data strucutres, etc.    */
  11. #include <graphics/displayinfo.h>   /* Release 2 Amiga display mode ID's  */
  12. #include <libraries/dos.h>          /* Official return codes defined here */
  13.  
  14. #include <clib/exec_protos.h>       /* Exec function prototypes           */
  15. #include <clib/intuition_protos.h>  /* Intuition function prototypes      */
  16.  
  17. /* Force use of new variable names to help prevent errors  */
  18. #define INTUI_V36_NAMES_ONLY
  19.  
  20. #ifdef LATTICE                      /* Disable Ctrl-C handling in SAS/C   */
  21. int CXBRK(void)  {return(0);}
  22. void chkabort(void) {return;}
  23. #endif
  24.  
  25. /* Use lowest non-obsolete version that supplies the functions needed. */
  26. #define INTUITION_REV 37
  27.  
  28. /* Declare the prototypes of our own functions.  Prototypes for system */
  29. /* functions are declared in the header files in the clib directory.   */
  30. VOID cleanExit( struct Screen *, struct Window *, LONG );
  31. BOOL handleIDCMP( struct Window *);
  32.  
  33. struct Library *IntuitionBase = NULL;
  34.  
  35. /* Position and sizes for our window */
  36. #define WIN_LEFTEDGE   20
  37. #define WIN_TOPEDGE    20
  38. #define WIN_WIDTH     400
  39. #define WIN_MINWIDTH   80
  40. #define WIN_HEIGHT    150
  41. #define WIN_MINHEIGHT  20
  42.  
  43.  
  44. VOID main(int argc, char *argv[])
  45. {
  46.     /* Declare variables here */
  47.     ULONG signalmask, winsignal, signals;
  48.     BOOL done = FALSE;
  49.     UWORD pens[]={~0};
  50.  
  51.     struct Screen *screen1 = NULL;
  52.     struct Window *window1 = NULL;
  53.  
  54.     /* Open the Intuition Library */
  55.     IntuitionBase = OpenLibrary( "intuition.library",INTUITION_REV );
  56.     if (IntuitionBase == NULL)
  57.         cleanExit(screen1, window1, RETURN_WARN);
  58.  
  59.     /* Open any other required libraries and make */
  60.     /* any assignments that were postponed above  */
  61.  
  62.     /* Open the screen */
  63.     screen1 = OpenScreenTags(NULL,
  64.                              SA_Pens,  (ULONG)pens,
  65.                              SA_DisplayID, HIRES_KEY,
  66.                              SA_Depth, 2,
  67.                              SA_Title, (ULONG)"Our Screen",
  68.                              TAG_DONE);
  69.  
  70.     if (screen1 == NULL)
  71.         cleanExit(screen1, window1, RETURN_WARN);
  72.  
  73.     /* ... and open the window */
  74.     window1 = OpenWindowTags(NULL,
  75.                              /* Specify window dimensions and limits */
  76.                              WA_Left,         WIN_LEFTEDGE,
  77.                              WA_Top,          WIN_TOPEDGE,
  78.                              WA_Width,        WIN_WIDTH,
  79.                              WA_Height,       WIN_HEIGHT,
  80.                              WA_MinWidth,     WIN_MINWIDTH,
  81.                              WA_MinHeight,    WIN_MINHEIGHT,
  82.                              WA_MaxWidth,     ~0,
  83.                              WA_MaxHeight,    ~0,
  84.                              /* Specify the system gadgets we want */
  85.                              WA_CloseGadget,  TRUE,
  86.                              WA_SizeGadget,   TRUE,
  87.                              WA_DepthGadget,  TRUE,
  88.                              WA_DragBar,      TRUE,
  89.                              /* Specify other attributes           */
  90.                              WA_Activate,     TRUE,
  91.                              WA_NoCareRefresh,TRUE,
  92.  
  93.                              /* Specify the events we want to know about */
  94.                              WA_IDCMP,        IDCMP_CLOSEWINDOW,
  95.  
  96.                              /* Attach the window to the open screen ...*/
  97.                              WA_CustomScreen, screen1,
  98.                              WA_Title,        "EasyWindow",
  99.                              WA_ScreenTitle,  "Our Screen - EasyWindow is Active",
  100.                              TAG_DONE);
  101.     if (window1 == NULL)
  102.         cleanExit(screen1, window1, RETURN_WARN);
  103.  
  104.     /* Set up the signals for the events we want to hear about ...   */
  105.     winsignal = 1L << window1->UserPort->mp_SigBit;  /* window IDCMP */
  106.     signalmask = winsignal;   /* we are only waiting on IDCMP events */
  107.  
  108.     /* Here's the main input event loop where we wait for events.    */
  109.     /* We have asked Intuition to send us CLOSEWINDOW IDCMP events   */
  110.     /* Exec will wake us if any event we are waiting for occurs.     */
  111.     while( !done )
  112.     {
  113.         signals = Wait(signalmask);
  114.  
  115.         /* An event occurred - now act on the signal(s) we received.*/
  116.         /* We were only waiting on one signal (winsignal) in our    */
  117.         /* signalmask, so we actually know we received winsignal.   */
  118.         if(signals & winsignal)
  119.             done = handleIDCMP(window1);    /* done if close gadget */
  120.     }
  121.     cleanExit(screen1, window1, RETURN_OK); /* Exit the program     */
  122. }
  123.  
  124. BOOL handleIDCMP( struct Window *win )
  125. {
  126.     BOOL done = FALSE;
  127.     struct IntuiMessage *message = NULL;
  128.     ULONG class;
  129.  
  130.     /* Examine pending messages */
  131.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) )
  132.     {
  133.         class = message->Class;  /* get all data we need from message */
  134.  
  135.         /* When we're through with a message, reply */
  136.         ReplyMsg( (struct Message *)message);
  137.  
  138.         /* See what events occurred */
  139.         switch( class )
  140.         {
  141.             case IDCMP_CLOSEWINDOW:
  142.                 done = TRUE;
  143.                 break;
  144.             default:
  145.                 break;
  146.         }
  147.     }
  148.     return(done);
  149. }
  150.  
  151. VOID cleanExit( struct Screen *scrn, struct Window *wind, LONG returnValue )
  152. {
  153.     /* Close things in the reverse order of opening */
  154.     if (wind) CloseWindow( wind );      /* Close window if opened */
  155.     if (scrn) CloseScreen( scrn );      /* Close screen if opened */
  156.  
  157.     /* Close the library, and then exit */
  158.     if (IntuitionBase) CloseLibrary( IntuitionBase );
  159.     exit(returnValue);
  160. }
  161.