home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / bgui-1.1a.lha / BGUI / demos / idcmphook.c < prev    next >
C/C++ Source or Header  |  1994-09-18  |  8KB  |  204 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc idcmphook.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: idcmphook.c,v $
  7. **      Description: Simple demonstration of a IDCMP hook
  8. **                   attached to a BGUI windowclass object.
  9. **        Copyright: (C) Copyright 1994 Jaba Development.
  10. **                   (C) Copyright 1994 Jan van den Baard.
  11. **                   All Rights Reserved.
  12. **
  13. **          $Author: jaba $
  14. **        $Revision: 1.2 $
  15. **            $Date: 1994/08/03 11:37:17 $
  16. **/
  17.  
  18. #include <libraries/bgui.h>
  19. #include <libraries/bgui_macros.h>
  20. #include <libraries/gadtools.h>
  21.  
  22. #include <clib/alib_protos.h>
  23.  
  24. #include <proto/exec.h>
  25. #include <proto/bgui.h>
  26. #include <proto/intuition.h>
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library                  *BGUIBase;
  37.  
  38. /*
  39. **      Object ID.
  40. **/
  41. #define ID_QUIT                 1
  42.  
  43. /*
  44. **      "tick" counter for the hook.
  45. **/
  46. UBYTE   Ticks = 0;
  47.  
  48. /*
  49. **      Simple example of the hook code.
  50. **/
  51. #ifdef _DCC
  52. __geta4 VOID hookFunc( __A0 struct Hook         *hook,
  53.                        __A2 Object              *obj,
  54.                        __A1 struct IntuiMessage *imsg )
  55. #else
  56. __saveds __asm VOID hookFunc( register __a0 struct Hook *hook,
  57.                               register __a2 Object      *obj,
  58.                               register __a1 struct IntuiMessage *imsg )
  59. #endif
  60. {
  61.         struct Window                   *wptr = NULL;
  62.  
  63.         /*
  64.         **      This hook is a simple IDCMP_INTUITICKS hook.
  65.         **      More complex hooks can receive several message
  66.         **      types depending on the setting of the
  67.         **      WINDOW_IDCMPHookBits attribute.
  68.         **
  69.         **      Simply beep the screen
  70.         **      every two seconds or so
  71.         **      while the window is active.
  72.         **/
  73.         if ( Ticks == 20 ) {
  74.                 Ticks = 0;
  75.                 /*
  76.                 **      Only flash the screen on which
  77.                 **      the window is located.
  78.                 **/
  79.                 GetAttr( WINDOW_Window, obj, ( ULONG * )&wptr );
  80.                 if ( wptr )
  81.                         DisplayBeep( wptr->WScreen );
  82.         }
  83.         Ticks++;
  84. }
  85.  
  86.  
  87. /*
  88. **      The hook structure.
  89. **
  90. ** typedef unsigned long (*HOOKFUNC)();
  91. **/
  92. struct Hook idcmpHook = {
  93.         NULL, NULL, (HOOKFUNC)hookFunc, NULL, NULL };
  94.  
  95. int main( int argc, char *argv[] )
  96. {
  97.         struct Window           *window;
  98.         Object                  *WO_Window, *GO_Quit;
  99.         ULONG                    signal = 0, rc, tmp = 0;
  100.         BOOL                     running = TRUE;
  101.  
  102.         /*
  103.         **      Open the library.
  104.         **/
  105.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  106.                 /*
  107.                 **      Create the window object.
  108.                 **/
  109.                 WO_Window = WindowObject,
  110.                         WINDOW_Title,           "IDCMPHook Demo",
  111.                         WINDOW_SizeGadget,      FALSE,
  112.                         WINDOW_IDCMP,           IDCMP_INTUITICKS,
  113.                         WINDOW_IDCMPHookBits,   IDCMP_INTUITICKS,
  114.                         WINDOW_IDCMPHook,       &idcmpHook,
  115.                         WINDOW_MasterGroup,
  116.                                 /*
  117.                                 **      A simple vertical group
  118.                                 **      containing a descriptive text
  119.                                 **      and a "Quit" button.
  120.                                 **/
  121.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  122.                                         StartMember, InfoFixed( NULL, "\33cThis small demo has a IDCMP-hook\n"
  123.                                                                       "installed which will flash the\n"
  124.                                                                       "display every two seconds while the\n"
  125.                                                                       "window is active.", NULL, 4 ), EndMember,
  126.                                         StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  127.                                 EndObject,
  128.                 EndObject;
  129.  
  130.                 /*
  131.                 **      Object created OK?
  132.                 **/
  133.                 if ( WO_Window ) {
  134.                         /*
  135.                         **      Assign a key to the button.
  136.                         **/
  137.                         if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  138.                                 /*
  139.                                 **      try to open the window.
  140.                                 **/
  141.                                 if ( window = WindowOpen( WO_Window )) {
  142.                                         /*
  143.                                         **      Obtain it's wait mask.
  144.                                         **/
  145.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  146.                                         /*
  147.                                         **      Event loop...
  148.                                         **/
  149.                                         do {
  150.                                                 Wait( signal );
  151.                                                 /*
  152.                                                 **      Handle events.
  153.                                                 **/
  154.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  155.                                                         /*
  156.                                                         **      Evaluate return code.
  157.                                                         **/
  158.                                                         switch ( rc ) {
  159.  
  160.                                                                 case    WMHI_CLOSEWINDOW:
  161.                                                                 case    ID_QUIT:
  162.                                                                         puts( "bye bye" );
  163.                                                                         running = FALSE;
  164.                                                                         break;
  165.                                                         }
  166.                                                 }
  167.                                         } while ( running );
  168.                                 } else
  169.                                         puts ( "Could not open the window" );
  170.                         } else
  171.                                 puts( "Could not assign gadget key" );
  172.                         /*
  173.                         **      Disposing of the window object will
  174.                         **      also close the window if it is
  175.                         **      already opened and it will dispose of
  176.                         **      all objects attached to it.
  177.                         **/
  178.                         DisposeObject( WO_Window );
  179.                 } else
  180.                         puts( "Could not create the window object" );
  181.                 CloseLibrary( BGUIBase );
  182.         } else
  183.                 puts( "Unable to open the bgui.library" );
  184.  
  185.         return( 0 );
  186. }
  187.  
  188. #ifdef _DCC
  189. int wbmain( struct wbStartup *wbs )
  190. {
  191.         return( main( 0, NULL ));
  192. }
  193. #endif
  194.  
  195. /*
  196.  *      $Log: idcmphook.c,v $
  197.  * Revision 1.2  1994/08/03  11:37:17  jaba
  198.  * Switched from clib/ to proto/.
  199.  *
  200.  * Revision 1.1  1994/06/20  16:43:03  jaba
  201.  * Initial revision
  202.  *
  203.  */
  204.