mymenu.start
上传用户:tjjs5310
上传日期:2021-05-16
资源大小:63k
文件大小:9k
源码类别:

BREW编程

开发平台:

C/C++

  1. /*===========================================================================
  2. FILE: mymenu.c
  3. ===========================================================================*/
  4. /*===============================================================================
  5. INCLUDES AND VARIABLE DEFINITIONS
  6. =============================================================================== */
  7. #include "AEEModGen.h"          // Module interface definitions
  8. #include "AEEAppGen.h"          // Applet interface definitions
  9. #include "AEEShell.h"           // Shell interface definitions
  10. #include "mymenu.bid"
  11. #include "mymenu_res.h"
  12. #include "AEEMenu.h"
  13. // defination for the menu items
  14. #define ID_ENTER 1
  15. #define ID_HELP  2
  16. #define ID_ABOUT 3
  17. /*-------------------------------------------------------------------
  18. Applet structure. All variables in here are reference via "pMe->"
  19. -------------------------------------------------------------------*/
  20. // create an applet structure that's passed around. All variables in
  21. // here will be able to be referenced as static.
  22. typedef struct _mymenu {
  23. AEEApplet      a ;        // First element of this structure must be AEEApplet
  24.     AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
  25.     IDisplay      *pIDisplay;  // give a standard way to access the Display interface
  26.     IShell        *pIShell;    // give a standard way to access the Shell interface
  27.     // add your own variables here...
  28. IMenuCtl       *pMenu;
  29.     int            state;
  30. } mymenu;
  31. /*-------------------------------------------------------------------
  32. Function Prototypes
  33. -------------------------------------------------------------------*/
  34. static  boolean mymenu_HandleEvent(mymenu* pMe, AEEEvent eCode, 
  35.                                              uint16 wParam, uint32 dwParam);
  36. boolean mymenu_InitAppData(mymenu* pMe);
  37. void    mymenu_FreeAppData(mymenu* pMe);
  38. static void BuildMainMenu(mymenu *pMe);
  39. /*===============================================================================
  40. FUNCTION DEFINITIONS
  41. =============================================================================== */
  42. /*===========================================================================
  43. FUNCTION: AEEClsCreateInstance
  44. DESCRIPTION
  45. This function is invoked while the app is being loaded. All Modules must provide this 
  46. function. Ensure to retain the same name and parameters for this function.
  47. In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
  48. that has been provided in AEEAppGen.c. 
  49.    After invoking AEEApplet_New(), this function can do app specific initialization. In this
  50.    example, a generic structure is provided so that app developers need not change app specific
  51.    initialization section every time except for a call to IDisplay_InitAppData(). 
  52.    This is done as follows: InitAppData() is called to initialize AppletData 
  53.    instance. It is app developers responsibility to fill-in app data initialization 
  54.    code of InitAppData(). App developer is also responsible to release memory 
  55.    allocated for data contained in AppletData -- this can be done in 
  56.    IDisplay_FreeAppData().
  57. PROTOTYPE:
  58.    int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
  59. PARAMETERS:
  60. clsID: [in]: Specifies the ClassID of the applet which is being loaded
  61. pIShell: [in]: Contains pointer to the IShell object. 
  62. pIModule: pin]: Contains pointer to the IModule object to the current module to which
  63. this app belongs
  64. ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
  65. of memory for this structure and initializing the base data members is done by AEEApplet_New().
  66. DEPENDENCIES
  67.   none
  68. RETURN VALUE
  69.   AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
  70.      successful
  71.   EFAILED: If the app does not need to be loaded or if errors occurred in 
  72.      AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
  73. SIDE EFFECTS
  74.   none
  75. ===========================================================================*/
  76. int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
  77. {
  78. *ppObj = NULL;
  79. if( ClsId == AEECLSID_MYMENU )
  80. {
  81. // Create the applet and make room for the applet structure
  82. if( AEEApplet_New(sizeof(mymenu),
  83.                           ClsId,
  84.                           pIShell,
  85.                           po,
  86.                           (IApplet**)ppObj,
  87.                           (AEEHANDLER)mymenu_HandleEvent,
  88.                           (PFNFREEAPPDATA)mymenu_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
  89.                           
  90. {
  91. //Initialize applet data, this is called before sending EVT_APP_START
  92.             // to the HandleEvent function
  93. if(mymenu_InitAppData((mymenu*)*ppObj))
  94. {
  95. //Data initialized successfully
  96. return(AEE_SUCCESS);
  97. }
  98. else
  99. {
  100. //Release the applet. This will free the memory allocated for the applet when
  101. // AEEApplet_New was called.
  102. IAPPLET_Release((IApplet*)*ppObj);
  103. return EFAILED;
  104. }
  105.         } // end AEEApplet_New
  106.     }
  107. return(EFAILED);
  108. }
  109. /*===========================================================================
  110. FUNCTION SampleAppWizard_HandleEvent
  111. DESCRIPTION
  112. This is the EventHandler for this app. All events to this app are handled in this
  113. function. All APPs must supply an Event Handler.
  114. PROTOTYPE:
  115. boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
  116. PARAMETERS:
  117. pi: Pointer to the AEEApplet structure. This structure contains information specific
  118. to this applet. It was initialized during the AEEClsCreateInstance() function.
  119. ecode: Specifies the Event sent to this applet
  120.    wParam, dwParam: Event specific data.
  121. DEPENDENCIES
  122.   none
  123. RETURN VALUE
  124.   TRUE: If the app has processed the event
  125.   FALSE: If the app did not process the event
  126. SIDE EFFECTS
  127.   none
  128. ===========================================================================*/
  129. static boolean mymenu_HandleEvent(mymenu* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
  130. {  
  131. uint16  item;
  132.     if(pMe->pMenu && IMENUCTL_HandleEvent(pMe->pMenu,eCode,wParam,dwParam) )
  133.     return TRUE;
  134.     switch (eCode) 
  135. {
  136.         // App is told it is starting up
  137.         case EVT_APP_START:                        
  138.     // Add your code here...
  139.             return(TRUE);
  140.         // App is told it is exiting
  141.         case EVT_APP_STOP:
  142.             // Add your code here...
  143.        return(TRUE);
  144.         // App is being suspended 
  145.         case EVT_APP_SUSPEND:
  146.     // Add your code here...
  147. pMe->pMenu = NULL;
  148.        return(TRUE);
  149.         // App is being resumed
  150.         case EVT_APP_RESUME:
  151.     // Add your code here...
  152.        return(TRUE);
  153.         // An SMS message has arrived for this app. Message is in the dwParam above as (char *)
  154.         // sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
  155.         case EVT_APP_MESSAGE:
  156.     // Add your code here...
  157.        return(TRUE);
  158.         // A key was pressed. Look at the wParam above to see which key was pressed. The key
  159.         // codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
  160.         case EVT_KEY:
  161.        return(FALSE);
  162.  case EVT_COMMAND:
  163.   return TRUE;
  164.         // If nothing fits up to this point then we'll just break out
  165.         default:
  166.             break;
  167.    }
  168.    return FALSE;
  169. }
  170. // this function is called when your application is starting up
  171. boolean mymenu_InitAppData(mymenu* pMe)
  172. {
  173.     // Get the device information for this handset.
  174.     // Reference all the data by looking at the pMe->DeviceInfo structure
  175.     // Check the API reference guide for all the handy device info you can get
  176.     // The display and shell interfaces are always created by
  177.     // default, so we'll asign them so that you can access
  178.     // them via the standard "pMe->" without the "a."
  179.     pMe->pIDisplay = pMe->a.m_pIDisplay;
  180.     pMe->pIShell   = pMe->a.m_pIShell;
  181.     // Insert your code here for initializing or allocating resources...
  182. pMe->pMenu = NULL;
  183.     pMe->state =0;
  184.     pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
  185.     ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
  186.     // if there have been no failures up to this point then return success
  187.     return TRUE;
  188. }
  189. // this function is called when your application is exiting
  190. void mymenu_FreeAppData(mymenu* pMe)
  191. {
  192.     // insert your code here for freeing any resources you have allocated...
  193.     // example to use for releasing each interface:
  194.     // if ( pMe->pIMenuCtl != NULL )         // check for NULL first
  195.     // {
  196.     //    IMENUCTL_Release(pMe->pIMenuCtl)   // release the interface
  197.     //    pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
  198.     // }
  199.     //
  200. if(pMe->pMenu != NULL)
  201. {
  202. IMENUCTL_Release(pMe->pMenu);
  203. pMe->pMenu = NULL;
  204. }
  205. }