⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.final

📁 brew 培训的sample source code
💻 FINAL
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: sample.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "sample.bid"
#include "sample_res.h"
#include "AEE.h"
#include "AEEMenu.h"
#include "AEEStdLib.h"
#include "AEEText.h"
// lab 1
#include "AEEImage.h"
#include "AEEMedia.h"
// end of lab 1

typedef struct _SampleApp
{
	AEEApplet      a;
	AEEDeviceInfo  info;
	IMenuCtl       *pMenu;
	IStatic        *pAbout;
	IStatic        *pHelp;
	// lab 2
	IImage         *pImage;
	IMedia         *pMedia;
	int            flag;      // whether to replay the music
	int            TickTime;  // record the tick numbers in order to play the music at the breakpoint 
	// end of lab 2
	ITextCtl       *pDogName;
	IMenuCtl       *pSoftkey;
	AECHAR         *pText;
	uint16         status;
}SampleApp;

// defination for the menu items
#define ID_NAME  1
#define ID_ENTER 2
#define ID_HELP  3
#define ID_ABOUT 4

// defination for the different pages
#define STATUS_SPLASH    5
#define STATUS_MAINMENU  6
#define STATUS_ABOUT     7
#define STATUS_HELP      8
#define STATUS_GIVENAME  9
// lab 3
#define STATUS_ENTER     10
// end of lab 3

// defination for the softkey
#define ID_OK             11

// the length for the dog's name
#define NAME_LEN         12

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean sample_HandleEvent(SampleApp * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

static boolean SampleApp_Init(SampleApp *pi);
static void SampleApp_Free(SampleApp *pi);
static void DisplaySplash(SampleApp *pi);
static void BuildMainMenu(SampleApp *pi);
static void DisplayAbout(SampleApp *pi);
static void DisplayHelp(SampleApp *pi);
static void SetDogName(SampleApp *pi);
static void DisplayDog(SampleApp *pi);
static void PlayImage(SampleApp *pi);
static void PlayMusic(SampleApp *pi);
static void MediaCallback(SampleApp *pi,AEEMediaCmdNotify *data);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

/*===========================================================================

FUNCTION: AEEClsCreateInstance

DESCRIPTION
	This function is invoked while the app is being loaded. All Modules must provide this 
	function. Ensure to retain the same name and parameters for this function.
	In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
	that has been provided in AEEAppGen.c. 

   After invoking AEEApplet_New(), this function can do app specific initialization. In this
   example, a generic structure is provided so that app developers need not change app specific
   initialization section every time except for a call to IDisplay_InitAppData(). 
   This is done as follows: InitAppData() is called to initialize AppletData 
   instance. It is app developers responsibility to fill-in app data initialization 
   code of InitAppData(). App developer is also responsible to release memory 
   allocated for data contained in AppletData -- this can be done in 
   IDisplay_FreeAppData().

PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
	clsID: [in]: Specifies the ClassID of the applet which is being loaded

	pIShell: [in]: Contains pointer to the IShell object. 

	pIModule: pin]: Contains pointer to the IModule object to the current module to which
	this app belongs

	ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
	of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
  none

RETURN VALUE
  AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
     successful
  EFAILED: If the app does not need to be loaded or if errors occurred in 
     AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_SAMPLE){
      if(AEEApplet_New(sizeof(SampleApp), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)sample_HandleEvent,(PFNFREEAPPDATA)SampleApp_Free)
         == TRUE)
      {
		 // Add your code here .....
		  if(!SampleApp_Init((SampleApp*)*ppObj))
		  {
			  IAPPLET_Release(*ppObj);
			  return EFAILED;
		  }

         return (AEE_SUCCESS);
      }
   }
	return (EFAILED);
}

/*===========================================================================

FUNCTION sample_HandleEvent

DESCRIPTION
	This is the EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.

PROTOTYPE:
	boolean sample_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pi: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

	ecode: Specifies the Event sent to this applet

   wParam, dwParam: Event specific data.

DEPENDENCIES
  none

RETURN VALUE
  TRUE: If the app has processed the event
  FALSE: If the app did not process the event

SIDE EFFECTS
  none
===========================================================================*/
static boolean sample_HandleEvent(SampleApp * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	uint16        item;

	if(pi->pDogName && ITEXTCTL_HandleEvent(pi->pDogName,eCode,wParam,dwParam) )
	    return TRUE;

	if(pi->pMenu && IMENUCTL_HandleEvent(pi->pMenu,eCode,wParam,dwParam) )
		return TRUE;

	if(pi->pSoftkey && IMENUCTL_HandleEvent(pi->pSoftkey,eCode,wParam,dwParam))
		return TRUE;

	switch (eCode) 
	{
      case EVT_APP_START:                        
		    
		    // Add your code here .....

			DisplaySplash(pi);
			ISHELL_SetTimer(pi->a.m_pIShell,1000,(PFNNOTIFY)BuildMainMenu,pi);
      		return(TRUE);
	  case EVT_KEY:
		  //When the user press clear key and the current page is not the main menu, it should be returned to the main menu.
		  if((wParam == AVK_CLR) && (pi->status != STATUS_MAINMENU)) 
		  {
			  if(pi->pDogName)
			  {
				  ITEXTCTL_SetActive(pi->pDogName,FALSE);
				  ITEXTCTL_Release(pi->pDogName);
				  IMENUCTL_Release(pi->pSoftkey);
				  pi->pDogName = NULL;
				  pi->pSoftkey = NULL;
			  }
			  if(pi->pAbout)
			  {
				  ISTATIC_Release(pi->pAbout);
				  pi->pAbout = NULL;
			  }
			  if(pi->pHelp)
			  {
				  ISTATIC_Release(pi->pHelp);
				  pi->pHelp = NULL;
			  }
			  // lab 9
			  if(pi->pImage)
			  {
				  IIMAGE_Stop(pi->pImage);
				  IIMAGE_Release(pi->pImage);
				  pi->pImage = NULL;
				  IMEDIA_Stop(pi->pMedia);
				  IMEDIA_Release(pi->pMedia);
				  pi->pMedia = NULL;
				  pi->flag = 1;   // do not replay the music 
			  }
			  // end of lab 9
			  IMENUCTL_Redraw(pi->pMenu);
			  IMENUCTL_SetActive(pi->pMenu,TRUE);
			  pi->status = STATUS_MAINMENU;
			  return TRUE;
		  }
		  else //When the user press clear key and the current page is main menu, the application should exit.
			  return FALSE;
	  case EVT_COMMAND:
		  if(IMENUCTL_IsActive(pi->pMenu))
		  {
			  item = IMENUCTL_GetSel (pi->pMenu);
			  switch(item)
			  {
			  case ID_NAME:  // Set the name for the dog
				  SetDogName(pi);
				  break;
			  case ID_ENTER:  // Display the running dog on the screen with the music
				  // lab 5
				  DisplayDog(pi);
				  // end of lab 5
				  break;
			  case ID_HELP:
				  DisplayHelp(pi);
				  break;
			  case ID_ABOUT:  // Display the information about this application
				  DisplayAbout(pi);
				  break;
			  default:
				  break;
			  }
			  return TRUE;
		  }
		  else if(IMENUCTL_IsActive(pi->pSoftkey))  
		  {
			  item = IMENUCTL_GetSel(pi->pSoftkey);
			  if(item == ID_OK)  // Get the name from the ITEXTCTL
			  {
				  if(!pi->pText)
				  pi->pText = (AECHAR*)MALLOC(NAME_LEN);
				  if(!pi->pText)
					  return FALSE;
				  ITEXTCTL_GetText(pi->pDogName,pi->pText,NAME_LEN/2);
				  ITEXTCTL_Release(pi->pDogName);
				  IMENUCTL_Release(pi->pSoftkey);
				  pi->pDogName = NULL;
				  pi->pSoftkey = NULL;
				  IMENUCTL_SetActive(pi->pMenu,TRUE);
			 	  return TRUE;
			  }
		  }
      case EVT_APP_STOP:

		    // Add your code here .....

         return TRUE;
	  case EVT_APP_SUSPEND:
		  switch(pi->status)
		  {
		  case STATUS_MAINMENU:
		      IMENUCTL_Release(pi->pMenu);
			  pi->pMenu = NULL;
			  break;
		  case STATUS_ABOUT:
			  ISTATIC_Release(pi->pAbout);
			  pi->pAbout = NULL;
			  break;
		  case STATUS_HELP:
			  ISTATIC_Release(pi->pHelp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -