📄 hellobrew.c
字号:
/*===========================================================================
FILE: hellobrew.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEStdLib.h"
#include "hellobrew.bid"
#include "hellobrew_res.h"
#define WBUFSZ 62 //定义缓冲大小
#define STAT_INSET 5 //定义屏幕边缘与静态控制器边界之间的象素数量
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _hellobrew {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
IDisplay *pIDisplay; // give a standard way to access the Display interface
IShell *pIShell; // give a standard way to access the Shell interface
// add your own variables here...
} hellobrew;
typedef struct
{
AEEApplet app ;
IStatic *m_pIStat;
}hb_app;
static boolean hb_InitAppData(hb_app *phb);
static void hb_FreeAppData(IApplet *pia);
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean hellobrew_HandleEvent(IApplet* pMe,
AEEEvent eCode, uint16 wParam,
uint32 dwParam);
boolean hellobrew_InitAppData(hellobrew* pMe);
void hellobrew_FreeAppData(hellobrew* pMe);
/*===============================================================================
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_HELLOBREW )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(hb_app),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)hellobrew_HandleEvent,
(PFNFREEAPPDATA)hb_FreeAppData)) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
{
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(hb_InitAppData((hb_app*)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION SampleAppWizard_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 SampleAppWizard_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 hellobrew_HandleEvent(IApplet* pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
hb_app *phb=(hb_app*)pi;
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
{
AEEDeviceInfo di;
AEERect r; // 用来确定静态控制器的大小和位置
AECHAR *wbufTtl=NULL,*wbufTxt=NULL; //确定几个缓存分别保存m_pIStat的标题和文本 wbufTtl和wbufTxt指向的是由宽字符集中的字符组成的以空结尾的字符串
if(!phb->app.m_pIShell) //验证m_pIShell的有效性
return FALSE;
ISHELL_GetDeviceInfo(phb->app.m_pIShell,&di); //调用m_pIShell来给di赋值
//设置装有静态控制器的位置、尺寸的矩形对象
r.x=r.y=STAT_INSET;
r.dx=di.cxScreen-2*STAT_INSET;
r.dy=di.cyScreen-2*STAT_INSET;
if(ISHELL_CreateInstance(phb->app.m_pIShell,AEECLSID_STATIC,(void**)&(phb->m_pIStat))!=SUCCESS)//指定AEECLSID_STATIC为请求接口的class ID
//假设成功,这个函数调用返回时m_pIStat将指向一个有效的IStatic 其它接口的class ID可以在aeeclassids.h中找到
{
return FALSE;
}
ISTATIC_SetRect(phb->m_pIStat,&r);//note 设置它的矩形,将指向刚才初始化的矩形结构的指针传递给他
wbufTtl=(AECHAR*)MALLOC(WBUFSZ);//
wbufTxt=(AECHAR*)MALLOC(WBUFSZ);
if(!(wbufTtl&&wbufTxt))
return FALSE;
if(!ISHELL_LoadResString(phb->app.m_pIShell,HELLOBREW_RES_FILE,STRING1,wbufTtl,WBUFSZ))//获取保存在指定资源文件中的 UNICODE 或 ISOLATIN 字符串。 返回的字符串将放置在提供的缓冲区中。
return FALSE;
if(!ISHELL_LoadResString(phb->app.m_pIShell,HELLOBREW_RES_FILE,STRING2,wbufTxt,WBUFSZ))
return FALSE;
if(!ISTATIC_SetText(phb->m_pIStat,wbufTtl,wbufTxt,AEE_FONT_BOLD,AEE_FONT_NORMAL))//两个缓冲区则将标题和文本提交给ISTATIC_SetText()。
return FALSE;
ISTATIC_SetProperties(phb->m_pIStat,ST_CENTERTEXT|ST_CENTERTITLE|ST_MIDDLETEXT);//此函数用于设置 IStatic 接口对象的属性。 属性值可以决定对象的实际外观和感觉。
ISTATIC_Redraw(phb->m_pIStat); //此函数用于刷新屏幕上的 IStatic 接口对象。
/*注意BREW不能容忍内存泄漏。因此你需要确信所有对MALLOC()的调用都相对应的有对FREE()的调用,
而对ISHELL_CreateInstance()的调用相对应的有对I*_Release()的调用。在EVT_APP_START的
最下面释放(FREE())了使用到的两个缓冲(buffer)。HelloBREW在hb_FreeAppData()中
调用Istatic_Release()时释放Istatic实例*/
FREE(wbufTtl);
wbufTtl=NULL;
FREE(wbufTxt);
wbufTxt=NULL;
// Add your code here...
return(TRUE);
}
// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...
return(TRUE);
// App is being suspended
case EVT_APP_SUSPEND:
// Add your code here...
return(TRUE);
// App is being resumed
case EVT_APP_RESUME:
// Add your code here...
return(TRUE);
// An SMS message has arrived for this app. Message is in the dwParam above as (char *)
// sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
// Add your code here...
return(TRUE);
// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
case EVT_KEY:
if(wParam==AVK_CLR)
// Add your code here...
return(FALSE);
// If nothing fits up to this point then we'll just break out
default:
break;
}
return FALSE;
}
// this function is called when your application is starting up
static boolean hb_InitAppData(hb_app *phb)
{
phb->m_pIStat=NULL;
return TRUE;
}
static void hb_FreeAppData(IApplet *pia)
{
hb_app *phb=(hb_app *)pia;
if(phb->m_pIStat)
{
ISTATIC_Release(phb->m_pIStat);
phb->m_pIStat=NULL;
}
}
boolean hellobrew_InitAppData(hellobrew* pMe)
{
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
// The display and shell interfaces are always created by
// default, so we'll asign them so that you can access
// them via the standard "pMe->" without the "a."
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
// Insert your code here for initializing or allocating resources...
// if there have been no failures up to this point then return success
return TRUE;
}
// this function is called when your application is exiting
void hellobrew_FreeAppData(hellobrew* pMe)
{
// insert your code here for freeing any resources you have allocated...
// example to use for releasing each interface:
// if ( pMe->pIMenuCtl != NULL ) // check for NULL first
// {
// IMENUCTL_Release(pMe->pIMenuCtl) // release the interface
// pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
// }
//
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -