Weird.. the second note I posted (the one about Rus' good point) came up
before the original code snip I posted... at any rate, I was looking in
detail at how to do this again, and realized the snippet probably didn't
explain it well.. so here is my event loop and associated functions:

static Boolean HandleHardKey(char chr)
{
   return 0;
}

static int AppPreProcessEvent(EventType *event)
{
   // Intercept hard keys to prevent them from switching apps
   if (event->eType == keyDownEvent)
   {
      if ((event->data.keyDown.chr >= hard1Chr &&
           event->data.keyDown.chr <= hard4Chr &&
           !(event->data.keyDown.modifiers & poweredOnKeyMask)))
      {
         if (HandleHardKey(event->data.keyDown.chr))
            return CMD_DONTHANDLE;
      }

      if (event->data.keyDown.chr == hardPowerChr ||
          event->data.keyDown.chr == autoOffChr)
         return CMD_POWEROFF;

      if (event->data.keyDown.chr == launchChr)
         return CMD_LAUNCHER;
   }
   return CMD_OK;
}

static void AppPostProcessEvent(int cmd)
{
   switch (cmd) {
   case CMD_LAUNCHER:
      // go to front form of application.. this is for Pre OS 3.0 support
      // where the launcher was not a separate application
      break;
   case CMD_POWEROFF:
      // post a stop event to your application
      break;
   }
}

static void EventLoop(void)
{
   EventType event;
   Word   error;
   int precmd;

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

      precmd = AppPreProcessEvent(&event);
      if (precmd == CMD_DONTHANDLE) continue;

      // Give the system a chance to handle the event.
      if (! SysHandleEvent(&event))
         // 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 (! ApplicationHandleEvent(&event))
               // Let the form object provide default handling of the event.
               FrmDispatchEvent(&event);

      AppPostProcessEvent(precmd);
   } while (event.eType != appStopEvent);
   StopApplication();
}




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

Reply via email to