home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / MUI / MCC_VLab / Developer / c / examples / main.c next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.5 KB  |  130 lines

  1. /*
  2. ** main.c - a module in VLab-Demo
  3. ** © Steve Quartly 1999
  4. **
  5. ** This code demonstrates the use of VLab.mcc
  6. **
  7. ** In it I build a custom class, based on MUIC_Window so I can invoke methods on my class.
  8. ** This is MUCH better than using hooks.
  9. **
  10. ** When writing in MUI, use sub classes!
  11. **
  12. */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <exec/memory.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <clib/iffparse_protos.h>
  21. #include <clib/muimaster_protos.h>
  22. #include <pragmas/muimaster_pragmas.h>
  23. #include <libraries/mui.h>
  24.  
  25. #include <mui/vlab_mcc.h>
  26.  
  27. #include "vlabwinclass.h"
  28.  
  29. struct Library *MUIMasterBase, *IntuitionBase;
  30.  
  31. /* The dispatcher for our custom class, VLabWinClass.*/
  32. extern ULONG __saveds __asm VLabWinDispatcher( register __a0 struct IClass *cl, register __a2 Object *obj, register __a1 Msg msg );
  33.  
  34. struct MUI_CustomClass *mccVLabWin;
  35.  
  36. /* Make sure MUI has enough stack.*/
  37. LONG __stack = 10000;
  38.  
  39. char *version = "$VER: VLab-Demo 1.0 (17.05.99)";
  40.  
  41. /*
  42. **
  43. ** main
  44. **
  45. */
  46.  
  47. int main( int argc, char *argv[] )
  48. {
  49.     Object *appObj, *winObj;
  50.  
  51.     /* Open the required libraries.*/
  52.     MUIMasterBase = OpenLibrary ( MUIMASTER_NAME, MUIMASTER_VMIN );
  53.     IntuitionBase = OpenLibrary ( "intuition.library", 39L );
  54.  
  55.     if ( MUIMasterBase && IntuitionBase )
  56.     {
  57.         /* Create our custom class, VLabWinClass.*/
  58.         mccVLabWin = MUI_CreateCustomClass( NULL, MUIC_Window, NULL, sizeof( struct VLabWinData ), VLabWinDispatcher );
  59.  
  60.         if ( mccVLabWin )
  61.         {
  62.             Object *vlabObj;
  63.  
  64.             /* Create our VLab.mcc object. This object does all the hard work for us and we
  65.                  should pass it to any objects that require it.*/
  66.             vlabObj = VLabObject, End;
  67.  
  68.             /* Now build the application.*/
  69.             appObj = ApplicationObject,
  70.                 MUIA_Application_Title, "VLab-Demo",
  71.                 MUIA_Application_Version, version,
  72.                 MUIA_Application_Copyright, "© 1999 Steve Quartly",
  73.                 MUIA_Application_Author, "Steve Quartly",
  74.                 MUIA_Application_Description, "Demonstrates the use of VLab.mcc",
  75.                 MUIA_Application_Base, "VLab-Demo",
  76.  
  77.                 /* Create an instance of our custom class, VLabWinClass, and pass into it
  78.                      our VLab.mcc object. It is a child of MUIC_Window, so it is effectively
  79.                      a WindowObject. This class is the back bone of this demo.*/
  80.                 SubWindow, winObj = NewObject( mccVLabWin->mcc_Class, NULL,
  81.                     VLAB_Object, vlabObj,
  82.                 TAG_DONE ),
  83.  
  84.             End;
  85.  
  86.             if ( appObj )
  87.             {
  88.                 ULONG signals = 0;
  89.  
  90.                 /* Now add the VLab.mcc object to the application.
  91.                      This MUST be done before any calls are made to this object.*/
  92.                 DoMethod( appObj, OM_ADDMEMBER, vlabObj );
  93.  
  94.                 /* The nofitication on the main window's close gadget.*/
  95.                 DoMethod( winObj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, appObj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  96.  
  97.                 /* Open the main window.*/
  98.                 set( winObj, MUIA_Window_Open, TRUE );
  99.  
  100.                 /* Our input loop.*/
  101.                 while ( DoMethod( appObj, MUIM_Application_NewInput, &signals ) != MUIV_Application_ReturnID_Quit )
  102.                 {
  103.                     if ( signals )
  104.                     {
  105.                         signals = Wait( signals | SIGBREAKF_CTRL_C );
  106.  
  107.                         if ( signals & SIGBREAKF_CTRL_C ) break;
  108.                     }
  109.                 }
  110.  
  111.                 /* All done, close the main window... not that we need to.*/
  112.                 set( winObj, MUIA_Window_Open, FALSE );
  113.  
  114.                 /* Dispose of the application.*/
  115.                 MUI_DisposeObject( appObj );
  116.             }
  117.  
  118.             /* Delete our custom class.*/
  119.             MUI_DeleteCustomClass( mccVLabWin );
  120.         }
  121.     }
  122.  
  123.     /* Close our libraries.*/
  124.     if ( MUIMasterBase ) CloseLibrary ( MUIMasterBase );
  125.     if ( IntuitionBase ) CloseLibrary ( IntuitionBase );
  126.  
  127.     /* We're outta here!.*/
  128. }
  129.  
  130.