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

  1.  
  2. /* greetings.c                                                         */
  3. /* Puts up a low-resolution window with a greeting, on a custom screen */
  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.  
  29. #include <exec/types.h>
  30. #include <intuition/intuition.h>
  31. #include <libraries/dos.h>
  32. #ifdef LATTICE
  33. #include <proto/all.h>
  34. #include <stdlib.h>
  35. int CXBRK(void) {return(0);}
  36. #endif
  37. /* Include other required vendor- or Commodore-Amiga-supplied header */
  38. /*  files here.                                                      */
  39.  
  40. /* Include user-written header files here. For illustration, we show */
  41. /*  two header files which we will use frequently.                   */
  42. #include "hires.h"
  43. #include "graniteWindow.h"
  44.  
  45. /* Use lowest non-obselete version that supplies the functions you need. */
  46. #define INTUITION_REV 33
  47. #define GRAPHICS_REV  33
  48.  
  49. extern VOID cleanExit( struct Screen *, struct Window *, int );
  50. extern UBYTE handleIDCMP( struct Window *);
  51.  
  52. struct IntuitionBase *IntuitionBase = NULL;
  53. struct GfxBase *GfxBase = NULL;
  54.         
  55. VOID main(int argc, char *argv[])
  56. {
  57.     /* Declare variables here */
  58.  
  59.     ULONG signalmask, signals;
  60.     UBYTE done = 0;
  61.     struct Screen *screen1 = NULL;
  62.     struct Window *window1 = NULL;
  63.  
  64.     /* Open the Intuition Library */
  65.  
  66.     IntuitionBase = (struct IntuitionBase *)
  67.                     OpenLibrary( "intuition.library",INTUITION_REV );
  68.  
  69.     if (IntuitionBase == NULL)
  70.         cleanExit(screen1, window1, RETURN_WARN);
  71.  
  72.  
  73.     /* Open any other required libraries */
  74.  
  75.     GfxBase = (struct GfxBase *)
  76.                 OpenLibrary("graphics.library",GRAPHICS_REV);
  77.  
  78.     if ( GfxBase == NULL )
  79.                 cleanExit(screen1, window1, RETURN_WARN);
  80.  
  81.     /* Make the assignments that were postponed above */
  82.  
  83.     fullHires.Width = 320;       /* Make custom screen low-res */
  84.     fullHires.ViewModes = NULL;
  85.     graniteWindow.Width /= 2;    /* Cut the window to fit      */
  86.  
  87.     /* Open the screen */
  88.  
  89.     screen1 = OpenScreen(&fullHires);
  90.     if (screen1 == NULL)
  91.         cleanExit(screen1, window1, RETURN_WARN);
  92.  
  93.  
  94.     /* Attach the window to the open screen ... */
  95.  
  96.     graniteWindow.Screen = screen1;
  97.  
  98.     /* ... and open the window */
  99.  
  100.     window1 = OpenWindow(&graniteWindow);
  101.     if (window1 == NULL)
  102.         cleanExit(screen1, window1, RETURN_WARN);
  103.  
  104.     /* Set up the signals that you want to hear about ... */
  105.  
  106.     signalmask = 1L << window1->UserPort->mp_SigBit;
  107.  
  108.     /* Call the functions that do the main processing */
  109.  
  110.     /* Write the message to the window */
  111.  
  112.     Move(window1->RPort, 20, 20);
  113.     Text(window1->RPort, "Hello World!", 12);
  114.  
  115.     /* And wait to hear from your signals */
  116.       
  117.     while( !done ) {
  118.  
  119.         signals = Wait(signalmask);    
  120.         if (signals & signalmask)
  121.             done = handleIDCMP(window1);
  122.     };
  123.  
  124.     /* Exit the program */
  125.  
  126.     cleanExit(screen1, window1, RETURN_OK);
  127.  
  128.  
  129. }
  130.  
  131. UBYTE handleIDCMP( struct Window *win )
  132. {
  133.     UBYTE flag = 0;
  134.     struct IntuiMessage *message = NULL;
  135.     ULONG class;
  136.  
  137.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) ) {
  138.  
  139.         class = message->Class;
  140.         ReplyMsg( (struct Message *)message);
  141.  
  142.         switch( class ) {
  143.         
  144.             case CLOSEWINDOW:
  145.             
  146.                 flag = 1;
  147.                 break;
  148.                 
  149.             default:
  150.             
  151.                 break;
  152.                 
  153.         }        
  154.     }
  155.  
  156.     return(flag);
  157. }
  158.  
  159. VOID cleanExit( scrn, wind, returnValue )
  160. struct Screen *scrn;
  161. struct Window *wind;
  162. int returnValue;
  163. {
  164.     /* Close things in the reverse order of opening */
  165.  
  166.     /* Close the window and the screen */
  167.  
  168.     if (wind) CloseWindow( wind );
  169.     if (scrn) CloseScreen( scrn );
  170.  
  171.     /* Close the library, and then exit */
  172.  
  173.     if (GfxBase) CloseLibrary( (struct Library *)GfxBase );
  174.     if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
  175.  
  176.     exit(returnValue);
  177.  
  178. }
  179.  
  180.