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

📄 resapp.c

📁 这是在BREW平台上写的一个小程序, 主要学会使用SDK工具,然后在模拟器上模拟.
💻 C
字号:
/*===========================================================================

FILE: resapp.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEDisp.h"
#include "AEEStdLib.h"
#include "AEEImage.h"
#include "resapp_res.h"
#include "resapp.bid"

#define szResFile "resapp.bar" 

typedef struct _CResApp
{
	AEEApplet a;
	int m_cxWidth;
	int m_cyHeight;
	int m_nCursorX;
	int m_nCursorY;
	IImage * m_pIImage;
}CResApp;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean resapp_HandleEvent(IApplet * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);
static boolean resapp_InitAppData(IApplet* pMe);
static void resapp_FreeAppData(IApplet* pMe);
static void Cresapp_Move(CResApp* pMe, int xc, int yc);

/*===============================================================================
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_RESAPP){
      if(AEEApplet_New(sizeof(CResApp), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)resapp_HandleEvent,(PFNFREEAPPDATA)resapp_FreeAppData) == TRUE)
	  {
		  if(resapp_InitAppData((IApplet*)*ppObj)==TRUE)
		  {
			  return (AEE_SUCCESS);
		  }
      }
   }
	return (EFAILED);
}

static boolean resapp_InitAppData(IApplet* pi)
{
	AEEDeviceInfo di;
	CResApp* pMe = (CResApp*)pi;

	pMe->m_pIImage = NULL;

	if(pMe->a.m_pIShell)
	{
		ISHELL_GetDeviceInfo(pMe->a.m_pIShell, &di);
		pMe->m_cxWidth = di.cxScreen;
		pMe->m_cyHeight = di.cyScreen;
	}

	pMe->m_nCursorX = pMe->m_cxWidth/2;
	pMe->m_nCursorY = pMe->m_cyHeight*2/3;

	if((pMe->m_pIImage = ISHELL_LoadResImage(pMe->a.m_pIShell,
		szResFile, IDB_CURSOR)) == NULL)
	{
		return FALSE;
	}
	return TRUE;
}

static void resapp_FreeAppData(IApplet* pi)
{
	CResApp* pMe = (CResApp*)pi;
	
	if(pMe->m_pIImage != NULL)
	{
		IIMAGE_Release(pMe->m_pIImage);
	}
}

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

FUNCTION resapp_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 resapp_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 resapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	AEERect rc;
	AECHAR szBuf[30] = {0};

	CResApp * pMe = (CResApp*)pi;

   switch (eCode) 
	{
      case EVT_APP_START:     
		  IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);

		  ISHELL_LoadResString(pMe->a.m_pIShell, RESAPP_RES_FILE,
			  IDS_STRING1, szBuf, sizeof(szBuf));
		  IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
			  -1, pMe->m_cxWidth/5, pMe->m_cyHeight/8, 0, 0);

		  ISHELL_LoadResString(pMe->a.m_pIShell, RESAPP_RES_FILE,
			  IDS_STRING2, szBuf, sizeof(szBuf));
		  IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL,szBuf,
			  -1, pMe->m_cxWidth/5, pMe->m_cyHeight/5, 0, 0);

		  SETAEERECT(&rc, 0, pMe->m_cyHeight/2 - 2, pMe->m_cxWidth, 2);
		  IDISPLAY_DrawRect(pMe->a.m_pIDisplay, &rc, 0, 1, IDF_RECT_FILL);

		  IIMAGE_Draw(pMe->m_pIImage, pMe->m_nCursorX, pMe->m_nCursorY);

		  IDISPLAY_Update(pMe->a.m_pIDisplay);		    
		    
      		return(TRUE);
	  case EVT_KEY:
		  switch(wParam)
		  {
		  case AVK_LEFT:
		  case AVK_RIGHT:
			  Cresapp_Move(pMe, (wParam == AVK_RIGHT ? 1 : -1), 0);
			  break;
		  case AVK_UP:
		  case AVK_DOWN:
			  Cresapp_Move(pMe, 0, (wParam == AVK_UP ? -1 : 1));
			  break;
		  default:
			  return(FALSE);
		  }
      case EVT_APP_STOP:

		    // Add your code here .....

         return TRUE;
      default:
         break;
   }
   return FALSE;
}

static void Cresapp_Move(CResApp* pMe, int xc, int yc)
{
	AEEImageInfo iInfo;
	int min, max;
	int x = pMe->m_nCursorX;
	int y = pMe->m_nCursorY;

	IIMAGE_GetInfo(pMe->m_pIImage, &iInfo);

	//IDISPLAY_EraseRgn(pMe->a.m_pIDisplay, x, y, iInfo.cx, iInfo.cy);

	x +=xc;
	y +=yc;

	min = 0;
	max = pMe->m_cxWidth - iInfo.cx;
	x = ((x , min) ? (min) : (x > max) ? max : (y));

	min = pMe->m_cyHeight/2;
	max = pMe->m_cyHeight - iInfo.cy;
	y = ((y < min) ? (min) : (y > max) ? max : (y));

	IIMAGE_Draw(pMe->m_pIImage, x, y);

	pMe->m_nCursorX = x;
	pMe->m_nCursorY = y;

	IDISPLAY_Update(pMe->a.m_pIDisplay);
}


⌨️ 快捷键说明

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