用C++写BREW 程序

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

FILE: MediaTest.h
===========================================================================*/
#ifndef __MEDIATEST_H__
#define __MEDIATEST_H__


#ifndef AEE_SIMULATOR
void* operator new (size_t size)
{
 return (void*)MALLOC(size);
}
void operator delete (void *pdata)
{
 FREE((void *)pdata);
}
#endif


typedef enum _TWindowtype{
    WIN_MAIN,

    WIN_MAX_VALUE
}TWindowtype;

typedef class MediaTest MediaTest;

//抽象窗口类
class CWindowInterface
{
public:
 ~CWindowInterface(){}
    virtual boolean OnInit(MediaTest* pApp) = 0;
    virtual void OnEnable(boolean bEnable) = 0;
 virtual void OnRedraw() = 0;
 virtual boolean OnHandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam)= 0;
 virtual boolean OnNotify(int nNotify) = 0 ;//需要数据通报,请覆盖此函数
};

//Applete 类
class MediaTest : public AEEApplet
{
public:
 static boolean MediaTest_HandleEvent(MediaTest *pMediaTest, AEEEvent eCode, uint16 wParam, uint32 dwParam);

public:
 //
 AEEDeviceInfo DeviceInfo;
    TWindowtype          m_eActiveWin;  // Active window
    TWindowtype          m_eSuspendWin; // Suspended window
    CWindowInterface* m_pWin;

};


//主窗口
class CMainWin : public CWindowInterface
{
public:
    CMainWin(){}
 virtual ~CMainWin(){}
public:
 boolean OnInit(MediaTest* pApp);
    virtual void OnEnable(boolean bEnable);
 virtual void OnRedraw();
 boolean OnHandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam);
 boolean OnNotify(int nNotify) {return 0;};
   
protected:
   IShell *       m_pIShell;
   IDisplay *     m_pIDisplay;
   flg            m_bActive:1;
};

#endif

 

 

//MediaTest.cpp

extern "C" int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
 *ppObj = NULL;

 if( ClsId == AEECLSID_MEDIATEST )
 {
  // Create the applet and make room for the applet structure
  if( AEEApplet_New(sizeof(MediaTest),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)MediaTest::MediaTest_HandleEvent,
                          (PFNFREEAPPDATA)MediaTest_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(MediaTest_InitAppData((MediaTest*)*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);
}

boolean MediaTest::MediaTest_HandleEvent(MediaTest* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)

 MediaTest* pMediaTest = static_cast<MediaTest*>(pMe);
    switch (eCode)
 {
        // App is told it is starting up
        case EVT_APP_START:                       
      // Add your code here...
   {
                MediaTest_SwitchApp(pMediaTest, WIN_MAIN);
   }

            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);


        // If nothing fits up to this point then we'll just break out
        default:
            break;
   }

   return FALSE;
}

 

void    MediaTest_SwitchApp(MediaTest* pMe, TWindowtype wt)
{
    switch(wt)   
 {
 case WIN_MAIN:
  {
   delete pMe->m_pWin;
   pMe->m_pWin = new CMainWin;
   pMe->m_pWin->OnInit(pMe);
   pMe->m_pWin->OnEnable(TRUE);
   pMe->m_pWin->OnRedraw();
  }
  break;
 default:
  {
  }
  break;
 }
}

void CMainWin::OnEnable(boolean bEnable)
{
 m_bActive = (flg)bEnable;
 DBGPRINTF("CMainWin::OnEnable!!");
}

boolean CMainWin::OnInit(MediaTest* pApp)
{
 assert(pApp->m_pIShell);
 m_pIShell = pApp->m_pIShell;
 assert(pApp->m_pIDisplay);
 m_pIDisplay = pApp->m_pIDisplay;
    m_bActive = (flg)0;
 return 0;
}

void CMainWin::OnRedraw(void)
{
 AECHAR text[] = L"Hello BREW C++";

 if(m_bActive)
 {
  IDISPLAY_DrawText (m_pIDisplay,
   AEE_FONT_LARGE,
   text,
   -1,
   0,
   0,
   NULL,
   IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE
   );
  IDISPLAY_Update(m_pIDisplay);
 }

}

boolean CMainWin::OnHandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
    boolean blRet = 0;

 return blRet;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值