********* ISSUES **********
- Debug mode: #define DEBUG_REXX
- Menus: write standard menu structure as default (user changes manually)
- LIBRARIES:
   Name              Version              Include?          DefVersion
   ----------------- -------------------- ----------------- --------------
   AslBase           {ASL_VERSION}        {ASL_INCL}           37
   DataTypesBase     {DATATYPES_VERSION}  {DATATYPES_INCL}     39
   DiskfontBase      {DISKFONT_VERSION}   {DISKFONT_INCL}      37
   DosBase           {DOS_VERSION}           N/A               37
   GadToolsBase      {GADTOOLS_VERSION}   {GADTOOLS_INCL}      37
   GfxBase           {GFX_VERSION}           N/A               37
   IconBase          {ICON_VERSION}          N/A               37
   IFFParseBase      {IFFPARSE_VERSION}   {IFFPARSE_INCL}      37
   IntuitionBase     {INTUITION_VERSION}     N/A               37
   LocaleBase        {LOCALE_VERSION}     {LOCALE_INCL}        38
   MUIMasterBase     {MUIMASTER_VERSION}     N/A            MUIMASTER_VMIN
   RealTimeBase      {REALTIME_VERSION}   {REALTIME_INCL}      37
   UtilityBase       {UTILITY_VERSION}       N/A               37
   WorkbenchBase     {WORKBENCH_VERSION}  {WORKBENCH_INCL}     37
--------------------------------------------------------------------------
{APPOWNER} = The owner of the program (for use in copyright in sourcecode), def "John M Haubrich Jr"
{COMPILER} = The compiler we're using, def "SAS/C 6.55"
{VERSNUM}  = version number only (string, i.e. "1.0"), def "1.0"
{YEAR}     = The year!
{REXX}     = TRUE if ARexx interface is included, else FALSE, def TRUE

{APPNAME}  = Application name, no default.  **REQUIRED**
{APPBASE}  = Application Base name, def "{APPNAME}"
{APPTITLE} = Application Title, def "{APPNAME}"
{APPVERS}  = Application version, def "$VER: {APPNAME} {VERSNUM} (DAY.MONTH.right(YEAR,2))",
{APPCOPYR} = Application copyright, def "(C) {YEAR}  {APPAUTH}",
{APPAUTH}  = Application author, def "John M Haubrich Jr"
{APPDESC}  = Application description, def "*** Description goes here! ***"
{HELPFILE} = Help file for this application, def "PROGDIR:{APPNAME}"

WSN = Window struct Name   \ i.e. struct MainWindow MAIN;
WSI = Window struct ID     /                WSN     WSI

WID = 32-bit window ID (MAKE_ID)
{WTITLE}   = Window Title, default to {WSN}
{MENUPTR}  = Identifier of menu for this window, defaults to Menu_{WSI}Menu,
{APPWDW}   = AppWindow (T | F), defaults to T
{WHELP}    = Help node for window, defaults to "{WSI}window"
{MHELP}    = Menu help node for this window, def "{WSI}menus"
{WCLOSE}   = ID to return upon window close gadget being pressed,
             defaults to MUIV_Application_ReturnID_Quit if {WSI} = "MAIN"
                    else ID_BUT_{WSI}_CANCEL
--------------------------------------------------------------------------

--------------------------------------------------------------------------
AREXX.C ------------------------------------------------------------------
--------------------------------------------------------------------------
/*
 * {APPNAME} ARexx  (C) {YEAR} {APPOWNER}
 *                  All Rights Under Copyright Reserved
 *
 * Version {VERSNUM}
 *
 * Written using {COMPILER}
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John M. Haubrich, Jr.
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 */

#include "common.h"

extern struct MyGlobals        MG;
extern char                    GL_szFault[256];


/*
 * AREXX HOOKS --------------------------------------
 */
SAVEDS ASM LONG RX_1ClearFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG ulForce;


   ulForce = *((ULONG *)arg);
   if ( ulForce )
   {
      return( RETURN_OK );
   }
   else if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                          "Are you sure you wish to clear all data?", NULL ) == 1 )
   {
      return( RETURN_OK );
   }

   return( RETURN_ERROR );
}
SAVEDS ASM LONG RX_1OpenFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulForce;
   char  *pszFile;


   pszFile =  ((char *)*arg);
   ulForce = *((ULONG *)(arg+1));

   if ( ulForce )
   {
      return( RETURN_OK );
   }
   else if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                          "Data has been modified.\nAre you sure you wish to continue?", NULL ) == 1 )
   {
      return( RETURN_OK );
   }

   return( RETURN_ERROR );
}
SAVEDS ASM LONG RX_1SaveasFunc     ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszFile;


   pszFile =  ((char *)*arg);

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_1QuitFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulForce;


   ulForce = *((ULONG *)arg);

   if ( !ulForce )
   {
      if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                        "Are you sure you want to quit?", NULL ) == 1 )
      {
         MG.running = FALSE;
      }
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4MoveWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lX, lY;
   char  *pszWindow;


   pszWindow =  ((char *)*arg);
   lX        = *((ULONG *)(arg+1));
   lY        = *((ULONG *)(arg+2));

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  MoveWindow( MG.WIN_{WSI}, lX, lY );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4SizeWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lW, lH;
   char  *pszWindow;


   pszWindow =  ((char *)*arg);
   lW        = *((ULONG *)(arg+1));
   lH        = *((ULONG *)(arg+2));

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  SizeWindow( MG.WIN_{WSI}, lW, lH );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ChangeWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lX, lY, lW, lH;
   char  *pszWindow;


   pszWindow =  ((char *)*arg);
   lX        = *((ULONG *)(arg+1));
   lY        = *((ULONG *)(arg+2));
   lW        = *((ULONG *)(arg+3));
   lH        = *((ULONG *)(arg+4));

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  ChangeWindow( MG.WIN_{WSI}, lX, lY, lW, lH );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4Wdw2FrontFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;


   pszWindow =  ((char *)*arg);

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  WindowToFront( MG.WIN_{WSI} );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4Wdw2BackFunc   ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;


   pszWindow =  ((char *)*arg);

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  WindowToBack( MG.WIN_{WSI} );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ActivateWdwFunc( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;


   pszWindow =  ((char *)*arg);

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  ActiveWindow( MG.WIN_{WSI} );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ZoomWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;


   pszWindow =  ((char *)*arg);

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  ZipWindow( MG.WIN_{WSI} );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4UnzoomWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;


   pszWindow =  ((char *)*arg);

@REPEAT-START
   if      ( strcmp( pszWindow, {WSI} ) == 0 ) {  ZipWindow( MG.WIN_{WSI} );  }
@REPEAT-END

   return( RETURN_OK );
}
SAVEDS ASM LONG RX_6LockGUIFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   set( MG.WIN_Main, MUIA_Application_Sleep, TRUE );
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_6UnlockGUIFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   set( MG.WIN_Main, MUIA_Application_Sleep, FALSE );
   return( RETURN_OK );
}


/*
 * AREXX PROTOS -------------------------------------
 */
static const struct Hook RX_1ClearHook       = { {NULL, NULL}, (void *)RX_1ClearFunc      , NULL, NULL };
static const struct Hook RX_1OpenHook        = { {NULL, NULL}, (void *)RX_1OpenFunc       , NULL, NULL };
static const struct Hook RX_1SaveasHook      = { {NULL, NULL}, (void *)RX_1SaveasFunc     , NULL, NULL };
static const struct Hook RX_1QuitHook        = { {NULL, NULL}, (void *)RX_1QuitFunc       , NULL, NULL };
static const struct Hook RX_4MoveWdwHook     = { {NULL, NULL}, (void *)RX_4MoveWdwFunc    , NULL, NULL };
static const struct Hook RX_4SizeWdwHook     = { {NULL, NULL}, (void *)RX_4SizeWdwFunc    , NULL, NULL };
static const struct Hook RX_4ChangeWdwHook   = { {NULL, NULL}, (void *)RX_4ChangeWdwFunc  , NULL, NULL };
static const struct Hook RX_4Wdw2FrontHook   = { {NULL, NULL}, (void *)RX_4Wdw2FrontFunc  , NULL, NULL };
static const struct Hook RX_4Wdw2BackHook    = { {NULL, NULL}, (void *)RX_4Wdw2BackFunc   , NULL, NULL };
static const struct Hook RX_4ActivateWdwHook = { {NULL, NULL}, (void *)RX_4ActivateWdwFunc, NULL, NULL };
static const struct Hook RX_4ZoomWdwHook     = { {NULL, NULL}, (void *)RX_4ZoomWdwFunc    , NULL, NULL };
static const struct Hook RX_4UnzoomWdwHook   = { {NULL, NULL}, (void *)RX_4UnzoomWdwFunc  , NULL, NULL };
static const struct Hook RX_6LockGUIHook     = { {NULL, NULL}, (void *)RX_6LockGUIFunc    , NULL, NULL };
static const struct Hook RX_6UnlockGUIHook   = { {NULL, NULL}, (void *)RX_6UnlockGUIFunc  , NULL, NULL };


/*
 * AREXX --------------------------------------------
 */
static struct MUI_Command rxcommands[] =
{
   // PROJECT-RELATED COMMANDS
   { "NEW",    MC_TEMPLATE_ID,         ID_MENU_NEW,   NULL            },
   { "CLEAR",  "FORCE/S",              1,             &RX_1ClearHook  },
   { "OPEN",   "FILENAME/A,FORCE/S",   2,             &RX_1OpenHook   },
   { "SAVE",   MC_TEMPLATE_ID,         ID_MENU_SAVE,  NULL            },
   { "SAVEAS", "NAME/A",               1,             &RX_1SaveasHook },
   { "CLOSE",  MC_TEMPLATE_ID,         ID_MENU_QUIT,  NULL            },
   { "QUIT",   "FORCE/S",              1,             &RX_1QuitHook   },

   // WINDOW-RELATED COMMANDS
   { "MOVEWINDOW",      "WINDOW/A,LEFTEDGE/N,TOPEDGE/N", 3, &RX_4MoveWdwHook     },
   { "SIZEWINDOW",      "WINDOW/A,WIDTH/N,HEIGHT/N",     3, &RX_4SizeWdwHook     },
   { "CHANGEWINDOW",    "WINDOW/A,LEFTEDGE/N,TOPEDGE/N,WIDTH/N,HEIGHT/N",
                                                         5, &RX_4ChangeWdwHook   },
   { "WINDOWTOFRONT",   "WINDOW/A",                      1, &RX_4Wdw2FrontHook   },
   { "WINDOWTOBACK",    "WINDOW/A",                      1, &RX_4Wdw2BackHook    },
   { "ACTIVATEWINDOW",  "WINDOW/A",                      1, &RX_4ActivateWdwHook },
   { "ZOOMWINDOW",      "WINDOW/A",                      1, &RX_4ZoomWdwHook     },
   { "UNZOOMWINDOW",    "WINDOW/A",                      1, &RX_4UnzoomWdwHook   },

   // APPLICATION-SPECIFIC COMMANDS

   // INTERFACE COMMANDS
   { "LOCKGUI",   "", 0, &RX_6LockGUIHook    },
   { "UNLOCKGUI", "", 0, &RX_6UnlockGUIHook  },

   { NULL, NULL, NULL, NULL }
};

RXCommands = (struct MUI_Command *)rxcommands;


--------------------------------------------------------------------------
COMMON.H -----------------------------------------------------------------
--------------------------------------------------------------------------
/*
 * {APPNAME} Common Headers   (C) {YEAR} {APPOWNER}
 *                            All Rights Under Copyright Reserved
 *
 * Version {VERSNUM}
 *
 * Written using {COMPILER}
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John M. Haubrich, Jr.
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 */

#include <exec/libraries.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <exec/lists.h>

#include <devices/keymap.h>

#include <graphics/gfxbase.h>
#include <graphics/displayinfo.h>

#include <intuition/intuitionbase.h>
#include <intuition/intuition.h>

#include <dos/dos.h>
#include <dos/datetime.h>
#include <dos/rdargs.h>
#include <dos/dostags.h>

#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>

#include <libraries/asl.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <libraries/gadtools.h>
#include <libraries/mui.h>

#include <rexx/storage.h>

#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>

#include <clib/alib_protos.h>

#include <proto/asl.h>
#include <proto/diskfont.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/icon.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>
#include <proto/utility.h>
#include <proto/wb.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <dos.h>
#include <math.h>


/*
 * GENERAL DEFINES ----------------------------------
 */
#define MAX( a,b )   ( ( (a) > (b) ) ? (a) : (b) )
#define MIN( a,b )   ( ( (a) < (b) ) ? (a) : (b) )
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))


#define REG(x) register __ ## x
#define ASM    __asm
#define SAVEDS __saveds

#define SimpleHelpButton(name,helpnode)\
	TextObject,\
		ButtonFrame,\
		MUIA_Text_Contents, name,\
		MUIA_Text_PreParse, "\33c",\
		MUIA_InputMode    , MUIV_InputMode_RelVerify,\
		MUIA_Background   , MUII_ButtonBack,\
      MUIA_HelpNode     , helpnode,\
		End

#define KeyHelpButton(name,key,helpnode)\
	TextObject,\
		ButtonFrame,\
		MUIA_Text_Contents, name,\
		MUIA_Text_PreParse, "\33c",\
		MUIA_Text_HiChar  , key,\
		MUIA_ControlChar  , key,\
		MUIA_InputMode    , MUIV_InputMode_RelVerify,\
		MUIA_Background   , MUII_ButtonBack,\
      MUIA_HelpNode     , helpnode,\
		End


/*
 * OBJECT IDs ------------------------------
 */
/***** MENUS *****/
***#define ID_MENU_MAIN_NEW                 1001
***#define ID_MENU_MAIN_OPEN                1002
***#define ID_MENU_MAIN_SAVE                1003
***#define ID_MENU_MAIN_SAVEAS              1004
***#define ID_MENU_MAIN_PRINTAS             1006
***#define ID_MENU_MAIN_ABOUT               1007
***#define ID_MENU_MAIN_QUIT                1008
... STD-MENUS ... ONE-BY-ONE INCLUSION

/*
 * MESSAGE IDs -----------------------------
 */
@REPEAT-START
/***** WINDOW: {WSI} *****/
#define ID_BUT_{WSI}_OK              10000 + 1000 * n + 998
#define ID_BUT_{WSI}_CANCEL          10000 + 1000 * n + 999
@REPEAT-END


/*
 * JMH-APP-TEMPLATE FUNCTION PROTOTYPES ----
 */
void  JMH_About( void );
LONG  JMH_Error( char *, APTR, BOOL, char *, char *, LONG );
void  JMH_InitVars( void );
ULONG JMH_LaunchProgram( BOOL, CHAR *, BOOL );
void  JMH_Startup( int, char ** );
void  JMH_Quit( char * );


/*
 * STRUCTURE DEFINITIONS -------------------
 */
struct MyGlobals {
   APTR  App;
@REPEAT-START
   APTR  WIN_{WSI};
@REPEAT-END

   struct DiskObject *dobj_App, *dobj_Proj;
   UBYTE  szProjectSpec[ FMSIZE+1 ];

   BOOL   running;
};

@REPEAT-START
struct {WSN} {
   APTR  BUT_OK,
         BUT_Cancel;
};
@REPEAT-END


/*
 * APPLICATION FUNCTION PROTOTYPES ------------------
 */
BOOL fnConstruct{WSN}( void );
BOOL fnInit{WSN}( void );
BOOL fnDestruct{WSN}( BOOL );
void fnClear{WSN}( void );


--------------------------------------------------------------------------
JMH.C --------------------------------------------------------------------
--------------------------------------------------------------------------
/*
 * JMH App Template  (C) {YEAR} {APPOWNER}
 *                   All Rights Under Copyright Reserved
 *
 * Version {VERSNUM}
 *
 * Written using {COMPILER}
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By {APPAUTH}
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 */

#include "common.h"

/**
 **   G L O B A L   V A R I A B L E S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 **/
extern struct MyGlobals MG;


#ifdef DEBUG_REXX
/**
 **   D E B U G   H O O K S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 **/
SAVEDS ASM APTR fnRexxDebug(REG(a0) struct Hook *hook, REG(a2) APTR app, REG(a1) struct RexxMsg *pRexxMsg )
{
   UBYTE *pszAppTitle;
   SHORT  i;


   get( app, MUIA_Application_Title, &pszAppTitle );
   printf( "***** MUI REXX DEBUG HOOK FOR %s *****\n", pszAppTitle );
   printf( "   rm_Action  = %ld\n", pRexxMsg->rm_Action );
   printf( "   rm_Result1 = %ld\n", pRexxMsg->rm_Result1 );
   printf( "   rm_Result2 = %ld\n", pRexxMsg->rm_Result2 );
   for ( i = 0; i < 15; i++ )
   {
      printf( "   rm_Args[%d] = '%s'\n", i, pRexxMsg->rm_Args[i] );
   }
   printf( "\n" );
   return(0);
}
static struct Hook hRexxDebugHook =
{
   {NULL, NULL},
   (void *)fnRexxDebug,
   NULL, NULL
};
#endif /* DEBUG_REXX */


/**
 **   S U B R O U T I N E S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 **/
//
// JMH_About(): show program info, basename, author, free memory, etc...
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void JMH_About( void )
{
   char  *pszVersion, *pszAuth, *pszCopyright, *pszBase, *pszDescrip;
   char   szAbout[1024];
   ULONG  ulChipFree, ulFastFree;


   get( MG.App, MUIA_Application_Version,     &pszVersion );
   get( MG.App, MUIA_Application_Author,      &pszAuth );
   get( MG.App, MUIA_Application_Copyright,   &pszCopyright );
   get( MG.App, MUIA_Application_Base,        &pszBase );
   get( MG.App, MUIA_Application_Description, &pszDescrip );

   ulChipFree = AvailMem( MEMF_CHIP );
   ulFastFree = AvailMem( MEMF_FAST );

   sprintf( szAbout, "\33c\33b%s\n\33c%s\n\33c%s\n\n\33c%s %s\n\n%s\n\n\
Graphics memory: %lu\nOther memory: %lu\n\nUsing Magic User Interface (MUI) by Stefan Stuntz",
                     pszVersion+6,
                     pszAuth,
                     pszCopyright,
                     "BASENAME:",
                     pszBase,
                     pszDescrip,
                     ulChipFree,
                     ulFastFree
          );

   MUI_Request( MG.App, NULL, 0, NULL, "*OK", szAbout, NULL );
}

//
// JMH_Error(): error routine that also provides help
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LONG JMH_Error( char *pszMsg, APTR pWindowObj, BOOL fARexx,
                char *pszHelpFile, char *pszHelpNode, LONG lHelpLine )
{
   LONG l;


   if ( fARexx )
   {
      set( MG.App, MUIA_Application_RexxMsg, pszMsg );
   }
   else
   {
redisplay:
      l = MUI_Request( MG.App, pWindowObj, 0, NULL, "*OK|Help", pszMsg, NULL );
      if ( l == 0 )
      {
         if ( pszHelpFile && pszHelpNode )
         {
            DoMethod( MG.App, MUIM_Application_ShowHelp, pWindowObj,
                      pszHelpFile, pszHelpNode, lHelpLine );
         }
         else
         {
            MUI_Request( MG.App, pWindowObj, 0, NULL, "*OK", "No help is available for this topic.", NULL );
         }
         goto redisplay;
      }
   }
   return( l );
}

//
// JMH_InitVars(): initialize variables to default values
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VOID JMH_InitVars()
{
   //
   // initialize variables...
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   GL_szFault[0] = 0;

   //
   // init window objects to NULL
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@REPEAT-START
   MG.WIN_{WSI} = NULL;
@REPEAT-END

   //
   // open libraries
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   MUIMasterBase = OpenLibrary(MUIMASTER_NAME, {MUIMASTER_VERSION});
   if (!MUIMasterBase) JMH_Quit("Cannot open muimaster.library" );

#if {ASL_INCL}
   AslBase = OpenLibrary("asl.library",{ASL_VERSION});
   if (!AslBase) JMH_Quit("Cannot open asl.library {ASL_VERSION}+");
#endif

#if {DATATYPES_INCL}
   DataTypesBase = (struct Library *)OpenLibrary("datatypes.library",{DATATYPES_VERSION});
   if (!DataTypesBase) JMH_Quit("Cannot open datatypes.library {DATATYPES_VERSION}+" );
#endif

#if {DISKFONT_INCL}
   DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", {DISKFONT_VERSION});
   if (!DiskfontBase) JMH_Quit("Cannot open diskfont.library {DISKFONT_VERSION}+");
#endif

   DosBase = (struct DosBase *)OpenLibrary( "dos.library", {DOS_VERSION} );
   if ( !DosBase ) JMH_Quit("Cannot open dos.library {DOS_VERSION}+");

#if {GADTOOLS_INCL}
   GadToolsBase = (struct Library *)OpenLibrary("gadtools.library", {GADTOOLS_VERSION});
   if (!GadToolsBase) JMH_Quit("Cannot open gadtools.library {GADTOOLS_VERSION}+");
#endif

   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",{GFX_VERSION});
   if (!GfxBase) JMH_Quit("Cannot open graphics.library {GFX_VERSION}+");

   IconBase = (struct Library *)OpenLibrary("icon.library",{ICON_VERSION});
   if (!IconBase) JMH_Quit("Cannot open icon.library {ICON_VERSION}+");

#if {IFFPARSE_INCL}
   IFFParseBase = (struct Library *)OpenLibrary("iffparse.library",{IFFPARSE_VERSION});
   if (!IFFParseBase) JMH_Quit("Cannot open iffparse.library {IFFPARSE_VERSION}+");
#endif

   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",{INTUITION_VERSION});
   if (!IntuitionBase) JMH_Quit("Cannot open intuition.library {INTUITION_VERSION}+");

#if {LOCALE_INCL}
   LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",{LOCALE_VERSION});
   if (!LocaleBase) JMH_Quit("Cannot open locale.library {LOCALE_VERSION}+");
#endif

#if {REALTIME_INCL}
   RealTimeBase = OpenLibrary("realtime.library", {REALTIME_VERSION});
   if (!RealTimeBase) JMH_Quit("Cannot open realtime.library {REALTIME_VERSION}+" );
#endif

   UtilityBase = (struct Library *)OpenLibrary("utility.library",{UTILITY_VERSION});
   if (!UtilityBase) JMH_Quit("Cannot open utility.library {UTILITY_VERSION}+" );

#if {WORKBENCH_INCL}
   WorkbenchBase = (struct Library *)OpenLibrary("workbench.library",{WORKBENCH_VERSION});
   if (!WorkbenchBase) JMH_Quit("Cannot open workbench.library {WORKBENCH_VERSION}+");
#endif
}

//
// JMH_LaunchProgram(): launch a system program
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ULONG JMH_LaunchProgram( BOOL fARexx, CHAR *pszProgram, BOOL fAsync )
{
   ULONG  rc = RETURN_OK;     // assume ARexx success...
   LONG   lStat;


   if ( !fAsync )    set( MG.App, MUIA_Application_Sleep, TRUE );

   lStat = SystemTags( szProgram, SYS_Asynch, fAsync, TAG_DONE, TAG_DONE );
   if ( lStat != 0 )
   {
      if ( lStat > 0 )
         Fault( IoErr(),
                "Cannot launch %s tool because",
                pszProgram,
                GL_szFault,
                sizeof( GL_szFault ) );
      else
         sprintf( GL_szFault, "Unable to launch %s!", pszProgram );

      JMH_Error( GL_szFault, NULL, fARexx, {HELPFILE}, "errors", 0 );
      rc = RETURN_ERROR;
   }

   if ( !fAsync )    set( MG.App, MUIA_Application_Sleep, FALSE );

   return( rc );
}

//
// JMH_Quit(): close down everything we've opened and JMH_Quit
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void JMH_Quit( char *t )
{
   char  szQuitBuf[256+20];


   if (t)
   {
      sprintf( szQuitBuf, "%s\nExiting...", t );
      MUI_Request( MG.App, NULL, 0, NULL, "*OK", szQuitBuf, NULL );
   }

   // free app object
   if ( MG.App )        MUI_DisposeObject( MG.App );

   // free disk object (project icon)
   if ( MG.dobj_Proj )  FreeDiskObject( MG.dobj_Proj );

   // free disk object (icon)
   if ( MG.dobj_App )   FreeDiskObject( MG.dobj_App );

   // close libraries
   if (WorkbenchBase)   CloseLibrary(WorkbenchBase);
   if (UtilityBase)     CloseLibrary(UtilityBase);
   if (RealTimeBase)    CloseLibrary(RealTimeBase);
   if (LocaleBase)      CloseLibrary(LocaleBase);
   if (IntuitionBase)   CloseLibrary((struct Library *)IntuitionBase);
   if (IFFParseBase)    CloseLibrary(IFFParseBase);
   if (IconBase)        CloseLibrary(IconBase);
   if (GfxBase)         CloseLibrary((struct Library *)GfxBase);
   if (GadToolsBase)    CloseLibrary(GadToolsBase);
   if (DosBase)         CloseLibrary((struct Library *)DosBase);
   if (DiskfontBase)    CloseLibrary(DiskfontBase);
   if (DataTypesBase)   CloseLibrary(DataTypesBase);
   if (AslBase)         CloseLibrary(AslBase);
   if (MUIMasterBase)   CloseLibrary(MUIMasterBase);

   exit(0);
}

//
// JMH_Startup(): handle arguments, setup environment, init vars/GUI...
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void JMH_Startup( int argc, char *argv[] )
{
   static char       *programname;
   static char        programpath[512];
   BPTR               tmplock;
   struct WBStartup  *WBenchMsg   = NULL;


   JMH_InitVars();

   GetProgramName( programpath, 512 );
   programname = FilePart( programpath );

   // try to get disk object (application icon)
   MG.dobj_App = GetDiskObject( programname );

   // try to get disk object (project icon)
   MG.dobj_Proj = GetDiskObjectNew( "PROGDIR:icons/def_project" );

   //
   // set up the MUI application object
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   MG.App = ApplicationObject,
      MUIA_Application_Title      , {APPTITLE},
      MUIA_Application_Version    , {APPVERS},
      MUIA_Application_Copyright  , {APPCOPYR},
      MUIA_Application_Author     , {APPAUTH},
      MUIA_Application_Description, {APPDESC},
      MUIA_Application_Base       , {APPBASE},
      MUIA_Application_DiskObject , MG.dobj_App,
#ifdef DEBUG_REXX
      MUIA_Application_RexxHook   , &hRexxDebugHook,
#endif
      MUIA_HelpFile               , {HELPFILE},
      End;

   if ( !MG.App )
      JMH_Quit( "Failed to create Application." );
}


--------------------------------------------------------------------------
MAIN.C -------------------------------------------------------------------
--------------------------------------------------------------------------
/*
 * {APPNAME} Main   (C) {YEAR} {APPOWNER}
 *                  All Rights Under Copyright Reserved
 *
 * Version {VERSNUM}
 *
 * Written using {COMPILER}
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John M. Haubrich, Jr.
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 */

#include "common.h"
#if {REXX}
extern struct MUI_Command *RXCommands;
#endif

/*
 * GLOBAL VARIABLES ---------------------------------
 */
struct MyGlobals  MG;
char              GL_szFault[256];

@REPEAT-START
struct {WSN}   {WSI};
@REPEAT-END


/*
 * DEFINES ------------------------------------------
 */
#define NUM_ARGS        0
//#define ARG_PUBSCREEN   0


/*
 * LIBRARY VARIABLES ---------------------------------
 */
struct Library       *AslBase       = NULL;
struct Library       *DataTypesBase = NULL;
struct Library       *DiskfontBase  = NULL;
struct DosBase       *DosBase       = NULL;
struct Library       *GadToolsBase  = NULL;
struct GfxBase       *GfxBase       = NULL;
struct Library       *IconBase      = NULL;
struct Library       *IFFParseBase  = NULL;
struct IntuitionBase *IntuitionBase = NULL;
struct Library       *LocaleBase    = NULL;
struct Library       *MUIMasterBase = NULL;
struct Library       *RealTimeBase  = NULL;
struct Library       *UtilityBase   = NULL;
struct Library       *WorkbenchBase = NULL;

#ifdef LATTICE
int CXBRK(void) { return(0); }
void __regargs __chkabort(void) { return; }
#endif

/**
 ** M A I N   P R O G R A M -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 **/
void main(int argc, char *argv[])
{
   ULONG   signals;
   ULONG   ulInputEvent;
   char    szBuf[256], szBuf2[50];

   struct DateTime  dt;

   // generic status vars
   LONG    lStat;
   ULONG   ulStat;
   char   *pszStat;

   BPTR               tmplock;
   struct WBStartup  *WBenchMsg   = NULL;
   struct WBArg      *pWBArg      = NULL;

   char               szProgramSpec[ FMSIZE+1 ];


   MG.running = TRUE;

   //
   // setup variables, read startup params, etc...
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   JMH_Startup( argc, argv );

   //
   // attempt to create window objects and attach to application parent
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@REPEAT-START
   if ( fnConstruct{WSN}() == FALSE )   {  JMH_Quit( "Failed to create {WSI} window." );  }
@REPEAT-END

   //
   // Load application settings; populate global vars
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   DoMethod( MG.App, MUIM_Application_Load, MUIV_Application_Load_ENV );

   //
   // open main window
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@REPEAT-START
   fnInit{WSN}();
@REPEAT-END

   //
   // if we're passed a data file, load it
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   if ( argc > 1 )
   {
//      fnReadData( argv[1], FALSE );
   }
   else
   {
      WBenchMsg   = (struct WBStartup *)argv;
      pWBArg      = WBenchMsg->sm_ArgList;

      pWBArg++;   // get first parameter

      if ( pWBArg )
      {
         if ( ( pWBArg->wa_Lock ) && ( *pWBArg->wa_Name ) )
         {
            tmplock  = Lock( pWBArg->wa_Name, ACCESS_READ );
            NameFromLock( tmplock, szProgramSpec, FMSIZE );
//            fnReadData( szProgramSpec, FALSE );
            UnLock( tmplock );
         }
      }
   }

   //
   // show 'em what it's all 'About'
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   JMH_About();

   //
   //   MAIN LOOP          MAIN LOOP         MAIN LOOP         MAIN LOOP
   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   while ( MG.running )
   {
      ulInputEvent = DoMethod( MG.App, MUIM_Application_Input, &signals );
      switch ( ulInputEvent )
      {
         case MUIV_Application_ReturnID_Quit:
         case ID_MENU_QUIT:
            if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                              "Are you sure you want to quit?", NULL ) == 1 )
            {
               MG.running = FALSE;
            }
            break;

         // MENUS ---------------------------------------------
         case ID_MENU_NEW:
            if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                              "Are you sure you wish to clear all data?", NULL ) == 1 )
            {
//               fnNew( FALSE );
            }
            break;
         case ID_MENU_OPEN:
            break;
         case ID_MENU_SAVE:
            break;
         case ID_MENU_SAVEAS:
            break;
         case ID_MENU_PRINTAS:
            fnLaunchProgram( FALSE, "SYS:Prefs/Printer", TRUE );
            break;
         case ID_MENU_ABOUT:
            JMH_About();
            break;
... STD-MENUS ... ONE-BY-ONE INCLUSION

         // GADGETS -------------------------------------------
@REPEAT-START
         /***** WINDOW: {WSI}        *****/
         case ID_BUT_{WSI}_OK:
            fnDestruct{WSN}( TRUE );
            break;
         case ID_BUT_{WSI}_CANCEL:
            fnDestruct{WSN}( FALSE );
            break;
@REPEAT-END
      }
      if ( MG.running && signals ) Wait(signals);
   }

   set( MG.WIN_Main, MUIA_Window_Open, FALSE );
   JMH_Quit( NULL );
}


--------------------------------------------------------------------------
WINDOWS.C ----------------------------------------------------------------
--------------------------------------------------------------------------
/*
 * {APPNAME} Windows   (C) {YEAR} {APPOWNER}
 *                     All Rights Under Copyright Reserved
 *
 * Version {VERSNUM}
 *
 * Written using {COMPILER}
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John M. Haubrich, Jr.
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 *
 *
 * Yeah, I know, icky title!
 */

#include "common.h"


******** PUT STANDARD MENUS HERE...
***struct NewMenu Menu_MainMenu[] = {
***   NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"New",            (STRPTR)"N", 0, 0L, (APTR)ID_MENU_MAIN_NEW,
***   NM_ITEM, (STRPTR)NM_BARLABEL,             NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"Open",           (STRPTR)"O", 0, 0L, (APTR)ID_MENU_MAIN_OPEN,
***   NM_ITEM, (STRPTR)"Save",           (STRPTR)"S", 0, 0L, (APTR)ID_MENU_MAIN_SAVE,
***   NM_ITEM, (STRPTR)"Save As...",     (STRPTR)"A", 0, 0L, (APTR)ID_MENU_MAIN_SAVEAS,
***   NM_ITEM, (STRPTR)NM_BARLABEL,             NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"Printer Setup...",      NULL, 0, 0L, (APTR)ID_MENU_MAIN_PRINTAS,
***   NM_ITEM, (STRPTR)NM_BARLABEL,             NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"About...",              NULL, 0, 0L, (APTR)ID_MENU_MAIN_ABOUT,
***   NM_ITEM, (STRPTR)NM_BARLABEL,             NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"Quit",           (STRPTR)"Q", 0, 0L, (APTR)ID_MENU_MAIN_QUIT,
***
***   NM_TITLE, (STRPTR)"Windows", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"Information..."      , (STRPTR)"I", 0, 0L, (APTR)ID_MENU_MAIN_INFORMATION,
***   NM_ITEM, (STRPTR)"History..."          , (STRPTR)"H", 0, 0L, (APTR)ID_MENU_MAIN_HISTORY,
***   NM_ITEM, (STRPTR)"Position..."         , (STRPTR)"P", 0, 0L, (APTR)ID_MENU_MAIN_POSITION,
***   NM_ITEM, (STRPTR)NM_BARLABEL           ,        NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"Regular Buy/Sell..." , (STRPTR)"R", 0, 0L, (APTR)ID_MENU_MAIN_REGBUYSELL,
***
***   NM_TITLE, (STRPTR)"Reports", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"Calculate Taxes"     , (STRPTR)"T", 0, 0L, (APTR)ID_MENU_MAIN_CALCTAXES,
***   NM_ITEM, (STRPTR)"InterNet Investing"  , (STRPTR)"V", 0, 0L, (APTR)ID_MENU_MAIN_INVESTING,
***
***   NM_TITLE, (STRPTR)"Settings", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"Chart"               , NULL, 0              , 0L, NULL,
***   NM_SUB , "One-at-a-time"               , NULL, CHECKIT|CHECKED, 2L, (APTR)ID_MENU_MAIN_SET_CHARTONE,
***   NM_SUB , "Overlay"                     , NULL, CHECKIT        , 1L, (APTR)ID_MENU_MAIN_SET_CHARTOVERLAY,
***   NM_ITEM, (STRPTR)"Tax Setup..."        , NULL, 0              , 0L, (APTR)ID_MENU_MAIN_SET_TAXSETUP,
***   NM_ITEM, (STRPTR)NM_BARLABEL           ,        NULL, 0, 0L, NULL,
***   NM_ITEM, (STRPTR)"Save Settings"       , NULL, 0              , 0L, (APTR)ID_MENU_MAIN_SET_SAVESETTINGS,
***
***   NM_TITLE, (STRPTR)"Macros", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"Run Macro...",                NULL, 0, 0L, (APTR)ID_MENU_MAIN_ASSIGNMACRO,
***
***   NM_TITLE, (STRPTR)"AppWindows", NULL, 0, NULL, NULL,
***   NM_ITEM, (STRPTR)"{WSN}..."            , NULL, 0, 0L, (APTR)ID_MENU_MAIN_{WSI},
***
***
***   NM_END, NULL, NULL, 0, 0L, NULL
***};


extern struct MyGlobals  MG;
extern char              GL_szFault[256];

@REPEAT-START
extern struct {WSN}           {WSI};
@REPEAT-END


@REPEAT-START
//
// WINDOW: {WSI}       ---------------------------------------------------
//
/*
 * APP MESSAGE HOOK FUNCTIONS -----------------------
 */
SAVEDS ASM LONG (WSI}_AppMsgFunc( REG(a2)APTR obj, REG(a1)struct AppMessage **appmsg )
{
   struct WBArg      *ap;
   struct AppMessage *amsg = *appmsg;
   static char        buf[256];
   BOOL               fSure = TRUE;    // sure you want to load this?


   ap = amsg->am_ArgList;
   NameFromLock( ap->wa_Lock, buf, sizeof( buf ) );
   AddPart( buf, ap->wa_Name, sizeof( buf ) );

// add condition here to choose whether or not to put up an "Are You Sure" message
   if ( 1 )
   {
      fSure = MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                           "Data is currently loaded.\nAre you sure you want to load the new file?", NULL );
   }
   if ( fSure == TRUE )
   {
      // load data file
      strcpy( MG.szProjectSpec, buf );
//      fnReadDataFromDisk( MG.szProjectSpec, MAIN.LIS_List, MUIV_List_Insert_Bottom );
   }

   return( 0 );
}

static const struct Hook {WSI}_AppMsgHook = { { NULL,NULL }, (VOID *){WSI}_AppMsgFunc, NULL, NULL };

BOOL fnConstruct{WSN}( void )
{
   MG.WIN_{WSI} = WindowObject,
      MUIA_Window_ID, MAKE_ID( {WID} ),
      MUIA_Window_Title, {WTITLE},
      MUIA_Window_Menu, {MENUPTR},
      MUIA_Window_AppWindow, {APPWDW},
      MUIA_HelpNode, {WHELP},
      WindowContents, VGroup,
//                ...
         End,
      End;

   if ( !MG.WIN_{WSI} )
   {
      return( FALSE );
   }
   else
   {
      // make gadget connections
      DoMethod( MG.WIN_{WSI}, MUIM_Notify, MUIA_AppMessage, MUIV_EveryTime,
                MG.App, 3, MUIM_CallHook, &{WSI}_AppMsgHook, MUIV_TriggerValue );

      DoMethod( MG.WIN_{WSI}, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
                MG.App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );

      DoMethod( {WSI}.BUT_OK    , MUIM_Notify, MUIA_Pressed, FALSE, MG.App, 2, MUIM_Application_ReturnID, ID_BUT_{WSI}_OK     );
      DoMethod( {WSI}.BUT_Cancel, MUIM_Notify, MUIA_Pressed, FALSE, MG.App, 2, MUIM_Application_ReturnID, ID_BUT_{WSI}_CANCEL );

      // set up help for menus
      DoMethod( MG.App, MUIM_Notify, MUIA_Application_MenuHelp, MUIV_EveryTime,
                MG.App, 5, MUIM_Application_ShowHelp, MG.WIN_{WSI}, {HELPFILE}, {MHELP}, 0 );

      // set tab cycle chain
      DoMethod( MG.WIN_{WSI}, MUIM_Window_SetCycleChain,
                {WSI}.BUT_OK,
                {WSI}.BUT_Cancel,
                NULL );

      // add window to Application object
      DoMethod( MG.App, OM_ADDMEMBER, MG.WIN_{WSI} );

      return( TRUE );
   }
}      

BOOL fnInit{WSN}( void )
{
//   set( MG.WIN_{WSI}, MUIA_Window_ActiveObject, {WSI}. );
   set( MG.WIN_{WSI}, MUIA_Window_Open, TRUE );

   return( TRUE );
}

void fnClear{WSN}( void )
{
}

BOOL fnDestruct{WSN}( BOOL fOKorCANCEL )
{
   switch( fOKorCANCEL )
   {
      case TRUE:     // OK
// verify data here
         set( MG.WIN_{WSI}, MUIA_Window_Open, FALSE );
         break;
      case FALSE:    // CANCEL
         set( MG.WIN_{WSI}, MUIA_Window_Open, FALSE );
         break;
   }

   return( fOKorCANCEL );
}
@REPEAT-END

