home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / cmanual.lha / CManual / IDCMP.lzh / IDCMP / Example9.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  6KB  |  180 lines

  1. /* Example9                                                           */
  2. /* This program explains how to use the IDCMP flag REFRESHWINDOW, and */
  3. /* how to optimize the redrawing of the window.                       */
  4.  
  5.  
  6.  
  7. #include <intuition/intuition.h>
  8.  
  9.  
  10.  
  11. struct IntuitionBase *IntuitionBase;
  12.  
  13.  
  14.  
  15. /* Declare a pointer to a Window structure: */ 
  16. struct Window *my_window;
  17.  
  18. /* Declare and initialize your NewWindow structure: */
  19. struct NewWindow my_new_window=
  20. {
  21.   50,             /* LeftEdge    x position of the window. */
  22.   25,             /* TopEdge     y positio of the window. */
  23.   320,            /* Width       320 pixels wide. */
  24.   100,            /* Height      100 lines high. */
  25.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  26.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  27.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  28.                   /*             selects the Close window gad.           */
  29.  
  30.   REFRESHWINDOW,  /*             We will recieve a message whenever we */
  31.                   /*             need to refresh (redraw) the window. */
  32.  
  33.   SIMPLE_REFRESH| /* Flags       Your program has to refresh the window. */
  34.   WINDOWCLOSE|    /*             Close Gadget. */
  35.   WINDOWDRAG|     /*             Drag gadget. */
  36.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  37.   WINDOWSIZING|   /*             Sizing Gadget. */
  38.   ACTIVATE,       /*             The window should be Active when opened. */
  39.   NULL,           /* FirstGadget No gadgets connected to this window. */
  40.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  41.   "UPDATE ME",    /* Title       Title of the window. */
  42.   NULL,           /* Screen      Connected to the Workbench Screen. */
  43.   NULL,           /* BitMap      No Custom BitMap. */
  44.   100,            /* MinWidth    We will not allow the window to become */
  45.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  46.   400,            /* MaxWidth    than 400 x 200. */
  47.   200,            /* MaxHeight */
  48.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  49. };
  50.  
  51.  
  52.  
  53. /*************************************************************************/
  54. /* Extra information:                                                    */
  55. /* We will recieve a REFRESHWINDOW message whenever we need to redraw    */
  56. /* the window's display. If the window is a SuperBitmap window you never */
  57. /* need to redraw it since it has its own BitMap. However, if the window */
  58. /* is of the type SIMPLE_REFRESH or SMART_REFRESH it can happen that     */
  59. /* your program need to redraw the window.                               */
  60. /* SIMPLE_REFRESH: You need to update the window if it is resized,       */
  61. /*                 pushed from behind to the front, or is moved.         */
  62. /* SMART_REFRESH:  You need to update the display if it is resized.      */
  63. /*                                                                       */
  64. /* Once you recieve the message you should redraw the window. However,   */
  65. /* before you start to redraw you need to call the function:             */
  66. /* BeginRefresh(), and when you have finished you should call the        */
  67. /* function EndRefresh(). (Even if you do not redraw anything, you       */
  68. /* should call these functions.) The functions will improve the speed of */
  69. /* the redrawing since only the trashed parts will be redrawed.          */
  70. /*************************************************************************/
  71.  
  72.  
  73.  
  74. main()
  75. {
  76.   /* Boolean variable used for the while loop: */
  77.   BOOL close_me;
  78.  
  79.   ULONG class;   /* IDCMP flag. */
  80.  
  81.   /* Pointer to an IntuiMessage structure: */
  82.   struct IntuiMessage *my_message;
  83.  
  84.  
  85.  
  86.   /* Before we can use Intuition we need to open the Intuition Library: */
  87.   IntuitionBase = (struct IntuitionBase *)
  88.     OpenLibrary( "intuition.library", 0 );
  89.   
  90.   if( IntuitionBase == NULL )
  91.     exit(); /* Could NOT open the Intuition Library! */
  92.  
  93.  
  94.  
  95.   /* We will now try to open the window: */
  96.   my_window = (struct Window *) OpenWindow( &my_new_window );
  97.   
  98.   /* Have we opened the window succesfully? */
  99.   if(my_window == NULL)
  100.   {
  101.     /* Could NOT open the Window! */
  102.     
  103.     /* Close the Intuition Library since we have opened it: */
  104.     CloseLibrary( IntuitionBase );
  105.  
  106.     exit();  
  107.   }
  108.  
  109.  
  110.  
  111.   /* We have opened the window, and everything seems to be OK. */
  112.  
  113.  
  114.  
  115.   close_me = FALSE;
  116.  
  117.   /* Stay in the while loop until the user has selected the Close window */
  118.   /* gadget: */
  119.   while( close_me == FALSE )
  120.   {
  121.     /* Wait until we have recieved a message: */
  122.     Wait( 1 << my_window->UserPort->mp_SigBit );
  123.  
  124.  
  125.     /* As long as we can collect messages successfully we stay in the */
  126.     /* while-loop: */
  127.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  128.     {
  129.       /* After we have successfully collected the message we can read */
  130.       /* it, and save any important values which we maybe want to check */
  131.       /* later: */
  132.       class = my_message->Class;     /* IDCMP flag. */
  133.       
  134.  
  135.       /* After we have read it we reply as fast as possible: */
  136.       /* REMEMBER! Do never try to read a message after you have replied! */
  137.       /* (Some other process has maybe changed it.) */
  138.       ReplyMsg( my_message );
  139.  
  140.  
  141.       /* Check which IDCMP flag was sent: */
  142.       switch( class )
  143.       {
  144.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  145.                close_me=TRUE;
  146.                break;
  147.  
  148.         case REFRESHWINDOW:  /* You need to update the window. */
  149.                printf("We need to redraw the window! (Well almost)\n");
  150.                
  151.                /* Start the redrawing: */
  152.                BeginRefresh( my_window );
  153.                
  154.                /* Redraw the window. For example call the function       */
  155.                /* RefreshGadgets(), DrawImage(), DrawBorder() etc...     */
  156.                /* In this example we do not redraw anything (there does  */
  157.                /* not exist anything to redraw). However, even if you do */
  158.                /* nothing you need to call the functions BeginRefresh()  */
  159.                /* and EndRefresh().                                      */
  160.                
  161.                /* End the redrawing: */
  162.                EndRefresh( my_window );
  163.                break;
  164.       }
  165.     }
  166.   }
  167.  
  168.  
  169.  
  170.   /* Close the window: */
  171.   CloseWindow( my_window );
  172.  
  173.  
  174.  
  175.   /* Close the Intuition Library: */
  176.   CloseLibrary( IntuitionBase );
  177.   
  178.   /* THE END */
  179. }
  180.