📄 test.c
字号:
/*===========================================================================
FILE: test.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" // AEE Stb Lib Services
#include "AEEMenu.h" // AEE Menu Services
#include "AEEFile.h" // AEE File Manager Services
#include "AEEImageCtl.h" // AEE ImageCtl Services
#include "AEEMIMETypes.h" // AEE MIME definitions
#include "test.bid"
#include "test_res.h"
/*-------------------------------------------------------------------
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 _IWindow IWindow;
QINTERFACE(IWindow)
{
// Enables/Disables the window. Window controls will not process
// events if the window is disabled.
void (*Enable)(IWindow * po, boolean bEnable);
// Redraws the window if enabled
void (*Redraw)(IWindow * po);
// Handles the events routed to the window
boolean (*HandleEvent)(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);
// Releases the window resources
void (*Delete)(IWindow * po);
};
#define IWINDOW_Enable(p) GET_PVTBL(p, IWindow)->Enable(p, TRUE)
#define IWINDOW_Disable(p) GET_PVTBL(p, IWindow)->Enable(p, FALSE)
#define IWINDOW_Redraw(p) GET_PVTBL(p, IWindow)->Redraw(p)
#define IWINDOW_HandleEvent(p, e, w, dw) GET_PVTBL(p, IWindow)->HandleEvent(p, e, w, dw)
#define IWINDOW_Delete(p) GET_PVTBL(p, IWindow)->Delete(p)
#define CT_IWINDOW_SETVTBL(pVtbl, pfnEn, pfnRd, pfnHE, pfnDel) \
(pVtbl)->Enable = (pfnEn); \
(pVtbl)->Redraw = (pfnRd); \
(pVtbl)->HandleEvent = (pfnHE); \
(pVtbl)->Delete = (pfnDel)
#define T_RELEASEIF(p) T_FreeIF((IBase **)&(p))
#define CT_ISEVTKEY(e) ((e) == EVT_KEY)
#define CT_ISEVTCMD(e) ((e) == EVT_COMMAND)
#define CTest_CancelRedraw(p) { CALLBACK_Cancel(&(p)->m_cbRedraw); (p)->m_bRedraw = FALSE; }
#define CT_DRAWHEADER(pme) CT_DrawImage((pme)->m_pOwner->m_pHdrImage, &(pme)->m_pOwner->m_rectHdr, TRUE)
#define CT_WINERR_RETURN(p) { CT_RELEASEWIN(p); return NULL; }
#define CT_RELEASEWIN(p) CT_FreeWin((IWindow **)&(p))
#define CTest_CancelRedraw(p) { CALLBACK_Cancel(&(p)->m_cbRedraw); (p)->m_bRedraw = FALSE; }
#define CTest_DisableWin(p) { IWINDOW_Disable((p)->m_pWin); CTest_CancelRedraw(p); }
#define CT_SPLASH_TIMER 750
#define CT_MAX_STRLEN 64
#define CT_HEADER_CY 16
#define CT_ICONVIEWCTL_CY 20
// Based on Menu style sheet:
#define MENU8_FT AEE_FT_NONE
#define MENU8_SELECT_FT AEE_FT_RAISED
#define MENU8_RO AEE_RO_TRANSPARENT
#define MENU8_SELECT_RO AEE_RO_TRANSPARENT
#define MENU8_COLOR_MASK (MC_BACK | MC_SEL_BACK | MC_SEL_TEXT)
#define MENU8_BACKGROUND MAKE_RGB(255,255,204)
#define MENU8_SELECT_BACKGROUND MAKE_RGB(153, 204, 204)
#define MENU8_SELECT_TEXT RGB_BLACK
#define TB8_BACKGROUND MAKE_RGB(192,192,192)
#define TB8_SELECT_BACKGROUND MAKE_RGB(192, 192, 192)
typedef enum _TWindow
{
MPW_NONE,
MPW_MAIN,
MPW_FILELIST,
MPW_PLAYER,
} TWindow;
typedef struct _test {
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...
int m_cxWidth;
int m_cyHeight;
uint16 m_nColorDepth;
uint16 m_wMainWin;
int m_nNChSize; // Large char size
int m_nLChSize; // Normal char size
IImage * m_pHdrImage;
AEERect m_rectHdr;
IImage * m_pLogo;
IMenuCtl * m_pMainMenu;
TWindow m_eActiveWin;
IWindow * m_pWin;
AEECallback m_cbRedraw;
flg m_bRedraw:1;
char * m_pszImageExt; // Registered image extension string: "bmp, png, ..."
flg m_bActive;
flg m_bPlugin:1; // = TRUE, in Plugin mode.
} test;
typedef struct CWindow CWindow;
typedef struct CMainWin CMainWin;
#define INHERIT_CWindow(iname) \
DECLARE_VTBL(iname) \
test * m_pOwner; \
IShell * m_pIShell; \
IDisplay * m_pIDisplay; \
flg m_bActive:1
// Base class of all IWindow objects.
struct CWindow
{
INHERIT_CWindow(IWindow);
};
// Main window: Displays main menu.
struct CMainWin
{
INHERIT_CWindow(IWindow);
IImage * m_pLogo;
AEERect m_rectLogo;
IMenuCtl * m_pMainMenu;
flg m_bAbout:1;
};
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean test_HandleEvent(test* pMe,
AEEEvent eCode, uint16 wParam,
uint32 dwParam);
boolean test_InitAppData(test* pMe);
void test_FreeAppData(test* pMe);
static void CTest_RedrawNotify(test * pme);
static boolean CTest_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID, AECHAR * pText, uint16 wImageID, uint16 wItemID, uint32 dwData);
static void CTest_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu, uint16 nColorDepth, AEERect * pRect, uint32 dwProps);
static IWindow * CMainWin_New(test * pOwner);
static IWindow * CWindow_New(int16 nSize, test * pOwner, VTBL(IWindow) * pvt);
static boolean CMainWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static void CMainWin_Delete(IWindow * po);
static void CMainWin_Redraw(IWindow * po);
static void CMainWin_Enable(IWindow * pMe, boolean bEnable);
static void CT_FreeWin(IWindow ** ppif);
static void T_FreeIF(IBase ** ppif);
static void CT_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter);
static void CMainWin_About(CMainWin * pme);
static boolean CTest_SetWindow(test * pme, TWindow eWin, uint32 dwParam);
static void CTest_Redraw(test * pme, boolean bDefer);
static void CTest_DrawSplash(test * pMe);
static boolean CWindow_ProcessEnable(IWindow * po, boolean bEnable);
/*===============================================================================
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_TEST )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(test),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)test_HandleEvent,
(PFNFREEAPPDATA)test_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(test_InitAppData((test*)*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 test_HandleEvent(test* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
{
AEEAppStart * pas = (AEEAppStart *)dwParam;
if (pas->pszArgs)
{
pMe->m_bPlugin = TRUE;
//CMediaPlayer_PlayFile(pMe, pas->pszArgs);
}
else
CTest_DrawSplash(pMe);
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:
// Add your code here...
return(TRUE);
case EVT_COPYRIGHT_END: // Copyright dialog ended
if (pMe->m_pWin)
return IWINDOW_HandleEvent(pMe->m_pWin, eCode, wParam, dwParam);
// 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
boolean test_InitAppData(test* pMe)
{
int nAscent, nDescent;
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
pMe->m_cxWidth = pMe->DeviceInfo.cxScreen;
pMe->m_cyHeight= pMe->DeviceInfo.cyScreen;
pMe->m_nColorDepth = pMe->DeviceInfo.nColorDepth;
// Insert your code here for initializing or allocating resources...
IDISPLAY_GetFontMetrics(pMe->a.m_pIDisplay, AEE_FONT_LARGE, &nAscent, &nDescent);
pMe->m_nLChSize = nAscent + nDescent;
IDISPLAY_GetFontMetrics(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, &nAscent, &nDescent);
pMe->m_nNChSize = nAscent + nDescent;
pMe->m_pHdrImage = ISHELL_LoadResImage(pMe->a.m_pIShell, TEST_RES_FILE, IDB_HEADER);
if (!pMe->m_pHdrImage)
return FALSE;
SETAEERECT(&pMe->m_rectHdr, 0, 0, pMe->m_cxWidth, CT_HEADER_CY);
CALLBACK_Init(&pMe->m_cbRedraw, (PFNNOTIFY)CTest_RedrawNotify, pMe);
pMe->m_pWin = CMainWin_New(pMe);
if (!pMe->m_pWin)
return FALSE;
//pMe->m_pMainMenu = ((CMainWin *)pMe->m_pWin)->m_pMainMenu;
return TRUE;
}
// this function is called when your application is exiting
void test_FreeAppData(test* pMe)
{
// insert your code here for freeing any resources you have allocated...
// example to use for releasing each interface:
if ( pMe->m_pMainMenu != NULL ) // check for NULL first
{
IMENUCTL_Release(pMe->m_pMainMenu); // release the interface
pMe->m_pMainMenu = NULL; // set to NULL so no problems trying to free later
}
T_RELEASEIF(pMe->m_pHdrImage);
T_RELEASEIF(pMe->m_pLogo);
CTest_CancelRedraw(pMe);
//CT_RELEASEWIN(pMe->m_pWin);
FREEIF(pMe->m_pszImageExt);
}
/*===========================================================================
This function releases IBase.
===========================================================================*/
static void T_FreeIF(IBase ** ppif)
{
if (ppif && *ppif)
{
IBASE_Release(*ppif);
*ppif = NULL;
}
}
/*===========================================================================
This function releases IWindow.
===========================================================================*/
static void CT_FreeWin(IWindow ** ppif)
{
if (ppif && *ppif)
{
IWINDOW_Delete(*ppif);
*ppif = NULL;
}
}
/*===========================================================================
This function draws the splash screen and brings up the main window
after the splash timer runs out.
===========================================================================*/
static void CTest_DrawSplash(test * pMe)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -