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

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