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

  1.  
  2. /* displayalert.c                              */
  3. /* This program implements a recoverable alert */
  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. */
  40. #include "hires.h"
  41. #include "graniteWindow.h"
  42.  
  43.  
  44. /* Each string requires its own positioning information, as explained  */
  45. /* in the manual. We use octal notation to specify the positions we    */
  46. /* want. Octal numbers start with a backslash and must be three digits */
  47. /* long. For the first line, x = \000\360 (two bytes, for 16 bits)     */
  48. /* and y = \020 (for one byte, eight bits), and the second line has    */
  49. /* x = \000\240 and y = \040.                                          */
  50.  
  51. UBYTE alertMsg[ ] = {
  52.       "\000\360\020OH NO, NOT AGAIN!  ",
  53. "\000\240\040PRESS LEFT MOUSE BUTTON TO CONTINUE.\000"
  54. };
  55.  
  56.  
  57. /* Use lowest non-obsolete version that supplies the functions you need. */
  58. #define INTUITION_REV 33
  59. #define PAUSE( seconds )  (Delay((seconds) * TICKS_PER_SECOND))
  60.  
  61. extern VOID cleanExit( struct Screen *, struct Window *, int );
  62. extern UBYTE handleIDCMP( struct Window *);
  63.  
  64. struct IntuitionBase *IntuitionBase = NULL;
  65.         
  66. VOID main(int argc, char *argv[])
  67. {
  68.     /* Declare variables here */
  69.     ULONG signalmask, signals;
  70.     UBYTE done = 0;
  71.     struct Screen *screen1 = NULL;
  72.     struct Window *window1 = NULL;
  73.  
  74.     /* Open the Intuition Library */
  75.     IntuitionBase = (struct IntuitionBase *)
  76.                     OpenLibrary( "intuition.library",INTUITION_REV );
  77.  
  78.     if (IntuitionBase == NULL)
  79.         cleanExit(screen1, window1, RETURN_WARN);
  80.  
  81.  
  82.  
  83.     /* Open any other required libraries */
  84.  
  85.  
  86.     /* Make the assignments that were postponed above */
  87.     alertMsg[21] = NULL;
  88.     alertMsg[22] = 0x01;
  89.  
  90.  
  91.     /* Open the screen */
  92.     screen1 = OpenScreen(&fullHires);
  93.     if (screen1 == NULL)
  94.         cleanExit(screen1, window1, RETURN_WARN);
  95.  
  96.  
  97.  
  98.     /* Attach the window to the open screen ... */
  99.     graniteWindow.Screen = screen1;
  100.  
  101.  
  102.     /* ... and open the window */
  103.     window1 = OpenWindow(&graniteWindow);
  104.     if (window1 == NULL)
  105.         cleanExit(screen1, window1, RETURN_WARN);
  106.  
  107.  
  108.     /* Set up the signals that you want to hear about ... */
  109.     signalmask = 1L << window1->UserPort->mp_SigBit;
  110.  
  111.  
  112.     /* Call the functions that do the main processing */
  113.     /* Delay a bit, so that the alert does not seem to appear */
  114.     /*  at the same time as the window                        */
  115.  
  116.     PAUSE( 3L );
  117.  
  118.     /* Mount the alert on the display */
  119.     DisplayAlert( RECOVERY_ALERT, alertMsg, 52 );
  120.  
  121.  
  122.     /* And wait to hear from your signals */      
  123.     while( !done ) {
  124.  
  125.         signals = Wait(signalmask);    
  126.         if (signals & signalmask)
  127.             done = handleIDCMP(window1);
  128.     };
  129.  
  130.  
  131.     /* Exit the program */
  132.     cleanExit(screen1, window1, RETURN_OK);
  133.  
  134.  
  135. }
  136.  
  137. UBYTE handleIDCMP( struct Window *win )
  138. {
  139.     UBYTE flag = 0;
  140.     struct IntuiMessage *message = NULL;
  141.     ULONG class;
  142.  
  143.     /* Examine pending messages */
  144.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) ) {
  145.  
  146.         class = message->Class;
  147.  
  148.         /* When we're through with a message, reply */
  149.         ReplyMsg( (struct Message *)message);
  150.  
  151.  
  152.         /* See what events occurred */
  153.         switch( class ) {
  154.         
  155.             case CLOSEWINDOW:
  156.             
  157.                 flag = 1;
  158.                 break;
  159.                 
  160.             default:
  161.             
  162.                 break;
  163.                 
  164.         }        
  165.     }
  166.  
  167.     return(flag);
  168. }
  169.  
  170. VOID cleanExit( scrn, wind, returnValue )
  171. struct Screen *scrn;
  172. struct Window *wind;
  173. int returnValue;
  174. {
  175.     /* Close things in the reverse order of opening */
  176.  
  177.  
  178.     /* Close the window and the screen */
  179.     if (wind) CloseWindow( wind );
  180.     if (scrn) CloseScreen( scrn );
  181.  
  182.  
  183.     /* Close the library, and then exit */
  184.     if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
  185.  
  186.  
  187.     exit(returnValue);
  188.  
  189. }
  190.  
  191.