/****************************************************************************** * * Copyright (c) 2007, ACCESS Systems Americas, Inc. All Rights Reserved. * * File: AppMain.c * *****************************************************************************/ #include #include #include "AppResources.h" /*********************************************************************** * * Entry Points * ***********************************************************************/ /*********************************************************************** * * Internal Constants * ***********************************************************************/ #define appFileCreator 'STRT' // register your own at http://www.palmos.com/dev/creatorid/ #define appVersionNum 0x01 #define appPrefID 0x00 #define appPrefVersionNum 0x01 /*********************************************************************** * * Internal Functions * ***********************************************************************/ /*********************************************************************** * * Internal Structures * ***********************************************************************/ /*********************************************************************** * * Private global variables * ***********************************************************************/ /*********************************************************************** * * FUNCTION: MainFormDoCommand * * DESCRIPTION: This routine performs the menu command specified. * * PARAMETERS: command - menu item id * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static Boolean MainFormDoCommand(UInt16 command) { Boolean handled = false; FormType * pForm; switch (command) { case MainOptionsAboutStarterApp: pForm = FrmInitForm(AboutForm); FrmDoDialog(pForm); // Display the About Box. FrmDeleteForm(pForm); handled = true; break; } return handled; } /*********************************************************************** * * FUNCTION: MainFormHandleEvent * * DESCRIPTION: This routine is the event handler for the * "MainForm" of this application. * * PARAMETERS: pEvent - a pointer to an EventType structure * * RETURNED: true if the event has handle and should not be passed * to a higher level handler. * * REVISION HISTORY: * * ***********************************************************************/ static Boolean MainFormHandleEvent(EventType* pEvent) { Boolean handled = false; FormType* pForm; switch (pEvent->eType) { case menuEvent: return MainFormDoCommand(pEvent->data.menu.itemID); case frmOpenEvent: pForm = FrmGetActiveForm(); FrmDrawForm(pForm); handled = true; break; default: break; case ctlSelectEvent: switch (pEvent->data.ctlSelect.controlID) { case ButtonDTMF1: { SndCommandType onCmd; onCmd.cmd = sndCmdNoteOn; onCmd.param1 = 60; onCmd.param2 = 2200; onCmd.param3 = 127; //This is where i need help SndDoCmd = (NULL, onCmd, noWait); // static Char bar[7]="button"; // 1 // WinDrawChars(bar, StrLen(bar), 130, 30); // 2 handled = true; break; } // other buttons... } break; } return handled; } /*********************************************************************** * * FUNCTION: AppHandleEvent * * DESCRIPTION: This routine loads form resources and set the event * handler for the form loaded. * * PARAMETERS: event - a pointer to an EventType structure * * RETURNED: true if the event has handle and should not be passed * to a higher level handler. * * REVISION HISTORY: * * ***********************************************************************/ static Boolean AppHandleEvent(EventType* pEvent) { UInt16 formId; FormType* pForm; Boolean handled = false; if (pEvent->eType == frmLoadEvent) { // Load the form resource. formId = pEvent->data.frmLoad.formID; pForm = FrmInitForm(formId); FrmSetActiveForm(pForm); // Set the event handler for the form. The handler of the currently // active form is called by FrmHandleEvent each time is receives an // event. switch (formId) { case MainForm: FrmSetEventHandler(pForm, MainFormHandleEvent); break; default: break; } handled = true; } return handled; } /*********************************************************************** * * FUNCTIONSSSSSSSSSSSSSSSSSSSSSSSSSSss * ***********************************************************************/ /*********************************************************************** * * FUNCTION: AppStart * * DESCRIPTION: Get the current application's preferences. * * PARAMETERS: nothing * * RETURNED: Err value errNone if nothing went wrong * * REVISION HISTORY: * * ***********************************************************************/ static Err AppStart(void) { FrmGotoForm(MainForm); return errNone; } /*********************************************************************** * * FUNCTION: AppStop * * DESCRIPTION: Save the current state of the application. * * PARAMETERS: nothing * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static void AppStop(void) { // Close all the open forms. FrmCloseAllForms(); } /*********************************************************************** * * FUNCTION: AppEventLoop * * DESCRIPTION: This routine is the event loop for the application. * * PARAMETERS: nothing * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static void AppEventLoop(void) { Err error; EventType event; do { EvtGetEvent(&event, evtWaitForever); if (SysHandleEvent(&event)) continue; if (MenuHandleEvent(0, &event, &error)) continue; if (AppHandleEvent(&event)) continue; FrmDispatchEvent(&event); } while (event.eType != appStopEvent); } /*********************************************************************** * * FUNCTION: PilotMain * * DESCRIPTION: This is the main entry point for the application. * * PARAMETERS: cmd - word value specifying the launch code. * cmdPB - pointer to a structure that is associated with the launch code. * launchFlags - word value providing extra information about the launch. * RETURNED: Result of launch * * REVISION HISTORY: * * ***********************************************************************/ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) { Err error = errNone; switch (cmd) { case sysAppLaunchCmdNormalLaunch: if ((error = AppStart()) == 0) { AppEventLoop(); AppStop(); } break; default: break; } return error; }