home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / intuition / intro / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  4.6 KB  |  168 lines

  1.  
  2. /* main.c                                                            */
  3. /* This is the program shell we'll be using with our examples.       */
  4. /* Compiled with Lattice C v5.02                                     */
  5. /* Compiler invoked with: lc -b1 -cfist -L -v -w                     */
  6.  
  7. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  8.  *
  9.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  10.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  11.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  12.  * information on the correct usage of the techniques and operating system
  13.  * functions presented in this example.  The source and executable code of
  14.  * this example may only be distributed in free electronic form, via bulletin
  15.  * board or as part of a fully non-commercial and freely redistributable
  16.  * diskette.  Both the source and executable code (including comments) must
  17.  * be included, without modification, in any copy.  This example may not be
  18.  * published in printed form or distributed with any commercial product.
  19.  * However, the programming techniques and support routines set forth in
  20.  * this example may be used in the development of original executable
  21.  * software products for Commodore Amiga computers.
  22.  * All other rights reserved.
  23.  * This example is provided "as-is" and is subject to change; no warranties
  24.  * are made.  All use is at your own risk.  No liability or responsibility
  25.  * is assumed.
  26.  */
  27.  
  28. #include <exec/types.h>
  29. #include <intuition/intuition.h>
  30. #include <libraries/dos.h>
  31. #ifdef LATTICE
  32. #include <proto/all.h>
  33. #include <stdlib.h>
  34. int CXBRK(void) {return(0);}
  35. #endif
  36. /* Include other required vendor- or Commodore-Amiga-supplied header */
  37. /*  files here.                                                      */
  38.  
  39. /* Include user-written header files here. For illustration, we show */
  40. /*  two header files which we will use frequently.                   */
  41. #include "hires.h"
  42. #include "graniteWindow.h"
  43.  
  44. /* Use lowest non-obselete version that supplies the functions you need. */
  45. #define INTUITION_REV 33
  46.  
  47. extern VOID cleanExit( struct Screen *, struct Window *, int );
  48. extern UBYTE handleIDCMP( struct Window *);
  49.  
  50. struct IntuitionBase *IntuitionBase = NULL;
  51.         
  52. VOID main(int argc, char *argv[])
  53. {
  54.     /* Declare variables here */
  55.     ULONG signalmask, signals;
  56.     UBYTE done = 0;
  57.     struct Screen *screen1 = NULL;
  58.     struct Window *window1 = NULL;
  59.  
  60.     /* Open the Intuition Library */
  61.     IntuitionBase = (struct IntuitionBase *)
  62.                     OpenLibrary( "intuition.library",INTUITION_REV );
  63.  
  64.     if (IntuitionBase == NULL)
  65.         cleanExit(screen1, window1, RETURN_WARN);
  66.  
  67.  
  68.  
  69.     /* Open any other required libraries */
  70.  
  71.  
  72.     /* Make the assignments that were postponed above */
  73.  
  74.  
  75.     /* Open the screen */
  76.     screen1 = OpenScreen(&fullHires);
  77.     if (screen1 == NULL)
  78.         cleanExit(screen1, window1, RETURN_WARN);
  79.  
  80.  
  81.  
  82.     /* Attach the window to the open screen ... */
  83.     graniteWindow.Screen = screen1;
  84.  
  85.  
  86.     /* ... and open the window */
  87.     window1 = OpenWindow(&graniteWindow);
  88.     if (window1 == NULL)
  89.         cleanExit(screen1, window1, RETURN_WARN);
  90.  
  91.  
  92.     /* Set up the signals that you want to hear about ... */
  93.     signalmask = 1L << window1->UserPort->mp_SigBit;
  94.  
  95.  
  96.     /* Call the functions that do the main processing */
  97.  
  98.  
  99.     /* And wait to hear from your signals */      
  100.     while( !done ) {
  101.  
  102.         signals = Wait(signalmask);    
  103.         if (signals & signalmask)
  104.             done = handleIDCMP(window1);
  105.     };
  106.  
  107.  
  108.     /* Exit the program */
  109.     cleanExit(screen1, window1, RETURN_OK);
  110.  
  111.  
  112. }
  113.  
  114. UBYTE handleIDCMP( struct Window *win )
  115. {
  116.     UBYTE flag = 0;
  117.     struct IntuiMessage *message = NULL;
  118.     ULONG class;
  119.  
  120.     /* Examine pending messages */
  121.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) ) {
  122.  
  123.         class = message->Class;
  124.  
  125.         /* When we're through with a message, reply */
  126.         ReplyMsg( (struct Message *)message);
  127.  
  128.  
  129.         /* See what events occurred */
  130.         switch( class ) {
  131.         
  132.             case CLOSEWINDOW:
  133.             
  134.                 flag = 1;
  135.                 break;
  136.                 
  137.             default:
  138.             
  139.                 break;
  140.                 
  141.         }        
  142.     }
  143.  
  144.     return(flag);
  145. }
  146.  
  147. VOID cleanExit( scrn, wind, returnValue )
  148. struct Screen *scrn;
  149. struct Window *wind;
  150. int returnValue;
  151. {
  152.     /* Close things in the reverse order of opening */
  153.  
  154.  
  155.     /* Close the window and the screen */
  156.     if (wind) CloseWindow( wind );
  157.     if (scrn) CloseScreen( scrn );
  158.  
  159.  
  160.     /* Close the library, and then exit */
  161.     if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
  162.  
  163.  
  164.     exit(returnValue);
  165.  
  166. }
  167.  
  168.