example of code:

#include <Pilot.h>    // all the system toolbox headers
#include "MemoPadRsc.h"   // application resource defines


/***********************************************************************
 * Global variables for this module
 **********************************************************************/
static MenuBarPtr  CurrentMenu = NULL; // P2. ptr to current menu


/***********************************************************************
 * Prototypes for internal functions
 **********************************************************************/
static void StartApplication(void);
static void SetCurrentMenu(Word rscID); // P2. set new current menu
static Boolean MainFormHandleEvent(EventPtr event);
static void EventLoop(void);


/***********************************************************************
 *
 * FUNCTION:     StartApplication
 *
 * DESCRIPTION:  This routine sets up the initial state of the application.
 *
 * PARAMETERS:   None.
 *
 * RETURNED:     Nothing.
 *
 ***********************************************************************/
static void StartApplication(void)
{
 FormPtr frm;

 // Initialize and draw the main memo pad form.
 frm = FrmInitForm(MemoPadMainForm);
 FrmSetActiveForm(frm);
 FrmDrawForm(frm);

 SetCurrentMenu(MainFormMenuBar);  // P2. set the current menu to the main
menu
}

/***********************************************************************
 *
 * FUNCTION:    SetCurrentMenu
 *
 * DESCRIPTION: P2. This routine loads the specified menu resource and makes
 *              it the current menu.
 *
 * PARAMETERS:  rscID  - resource id of the new menu
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
static void SetCurrentMenu(Word rscID)
{
 // Dispose of an existing current menu.
 if (CurrentMenu)
  MenuDispose(CurrentMenu);

 // Set the current menu and remember it.
 CurrentMenu = MenuInit(1000);//MenuInit(rscID);
}


/***********************************************************************
 *
 * FUNCTION:  MainFormHandleEvent
 *
 * DESCRIPTION: Handles processing of events for the ÒmainÓ form.
 *
 * PARAMETERS:  event  - the most recent event.
 *
 * RETURNED:  True if the event is handled, false otherwise.
 *
 ***********************************************************************/
static Boolean MainFormHandleEvent(EventPtr event)
{
 Boolean  handled = false;
 EventType newEvent;
 FormPtr  frm;

   if (event->eType == ctlSelectEvent)
    {
  // A control button is pressed and released.
  // The exit button being the only button, stop the application.
    MemSet(&newEvent, sizeof(EventType), 0);
    newEvent.eType = appStopEvent;
    EvtAddEventToQueue(&newEvent);
  handled = true;
    }

 else if (event->eType == menuEvent)  // P2. process menu events for this
form
  {
  // A menu item was selected.
  // The Òget infoÓ being the only menu item, display the info form.

  // First clear the menu status from the display.
  MenuEraseStatus(CurrentMenu);

  // Load the info form, then display it.
  frm = FrmInitForm(MemoPadInfoForm);
  FrmDoDialog(frm);

  // Delete the info form.
   FrmDeleteForm(frm);
  handled = true;
  }
 return handled;
}


/***********************************************************************
 *
 * FUNCTION:  EventLoop
 *
 * DESCRIPTION: A simple loop that obtains events from the Event
 *      Manager and passes them on to various applications and
 *      system event handlers before passing them on to
 *      FrmHandleEvent for default processing.
 *
 * PARAMETERS:  None.
 *
 * RETURNED:  Nothing.
 *
 ***********************************************************************/
static void EventLoop(void)
{
 EventType event;
 Word   error;

 do
  {
  // Get the next available event.
  EvtGetEvent(&event, evtWaitForever);

  // Give the system a chance to handle the event.
  if (! SysHandleEvent(&event))

   // P2. Give the menu bar a chance to update and handle the event.
   if (! MenuHandleEvent(CurrentMenu, &event, &error))

    // Give the application a chance to handle the event.
    if (! MainFormHandleEvent(&event))

     // Let the form object provide default handling of the event.
     FrmHandleEvent(FrmGetActiveForm(), &event);
  }
 while (event.eType != appStopEvent);
}


/***********************************************************************
 *
 * FUNCTION:  PilotMain
 *
 * DESCRIPTION: This function is the equivalent of a main() function
 *      under standard ÒCÓ.  It is called by the Emulator to begin
 *      execution of this application.
 *
 * PARAMETERS:  cmd - command specifying how to launch the application.
 *      cmdPBP - parameter block for the command.
 *      launchFlags - flags used to configure the launch.
 *
 * RETURNED:  Any applicable error code.
 *
 ***********************************************************************/
DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
{
 // Check for a normal launch.
 if (cmd == sysAppLaunchCmdNormalLaunch)
  {
  // Set up initial form.
  StartApplication();

  // Start up the event loop.
  EventLoop();
  }

 return 0;
}


--
Dan MacLeod

[EMAIL PROTECTED]
[EMAIL PROTECTED]
(561) 989-2640





-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to