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

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