zoukankan      html  css  js  c++  java
  • 我的BREW代码 荣

    1. 打印标题和内容:
      以下是C代码:
    // 打印标题和文本
    static void XMR_PrinterTITLEAndContent(hellobrew * pMe)
    {
     
    // 矩形区域
     AEERect r;

     
    // 文本变量
     AECHAR *wbufTtl = NULL, *wbufTxt = NULL, *test = NULL;
     r.x 
    = r.y = STAT_INSET;
     r.dx 
    = pMe->DeviceInfo.cxScreen - 2*STAT_INSET;
     r.dy 
    = pMe->DeviceInfo.cyScreen - 2*STAT_INSET;
     
    if (ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_STATIC,
      (
    void**&(pMe->m_pIStat)) != SUCCESS)
     {
      
    return FALSE;
     }

     ISTATIC_SetRect(pMe
    ->m_pIStat, &r);

     wbufTtl 
    = (AECHAR*)MALLOC(WBUFSZ);
     wbufTxt 
    = (AECHAR*)MALLOC(WBUFSZ);
     test 
    = (AECHAR*)MALLOC(WBUFSZ);

     ISHELL_LoadResString(pMe
    ->a.m_pIShell,
       HELLOBREW_RES_FILE, IDS_STRING_1001,
       wbufTtl, WBUFSZ);
     ISHELL_LoadResString(pMe
    ->a.m_pIShell,
       HELLOBREW_RES_FILE, IDS_STRING_1002,
       wbufTxt, WBUFSZ);

     ISHELL_LoadResString(pMe
    ->a.m_pIShell,
       EXPENSETRACKER_RES_FILE, IDC_ADD_NEW,
       test, WBUFSZ);

     ISTATIC_SetText(
      pMe
    ->m_pIStat,
      wbufTtl, 
      test, 
      AEE_FONT_BOLD, 
      AEE_FONT_NORMAL);

     ISTATIC_SetProperties(
      pMe
    ->m_pIStat, 
      ST_CENTERTITLE 
    | ST_CENTERTEXT | ST_MIDDLETEXT);

     ISTATIC_Redraw(pMe
    ->m_pIStat);
     FREE(wbufTtl);
     wbufTtl 
    = NULL;
     FREE(wbufTxt);
     wbufTxt 
    = NULL;
     FREE(test);
     test 
    = NULL;
    }



    这段代码中的主题和内容,读取自两个资源文件:ExpenseTracker.bar,hellobrew.bar
    宏EXPENSETRACKER_RES_FILE(资源文件名)、IDC_ADD_NEW(字符串编号)、HELLOBREW_RES_FIL(资源文件名)、IDS_STRING_1001(字符串编号)、IDS_STRING_1002(字符串编号)定义分别在expensetracker.brh和hellobrew.brh中设置。
    hellobrew结构:

    typedef struct _hellobrew {
        AEEApplet      a ;           
    // First element of this structure must be AEEApplet
        AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
        IStatic *m_pIStat; 
    } hellobrew;

    2.
    居中显示图片:
    代码:

    // 开始屏幕显示
    static void ET_DisplaySplashScreen(hellobrew * pApp)
    {
       IImage
    * pImage = NULL;
       AEEImageInfo rImageInfo;

       
    // Load the splash image from the rsource file
       pImage = ISHELL_LoadResImage( pApp->a.m_pIShell, EXPENSETRACKER_RES_FILE, IDB_SPLASH );

      
    // 清楚屏幕内容并在屏幕中心画图
      IDISPLAY_ClearScreen( pApp->a.m_pIDisplay );
      IIMAGE_GetInfo( pImage, 
    &rImageInfo );
      IIMAGE_Draw(pImage, ((pApp
    ->m_rScreenRect.x + pApp->m_rScreenRect.dx)/2- (rImageInfo.cx/2), ((pApp->m_rScreenRect.y + pApp->m_rScreenRect.dy)/2- (rImageInfo.cy/2));
      IDISPLAY_Update( pApp
    ->a.m_pIDisplay );
      IIMAGE_Release( pImage );  
    // the image is drawn so we don't need it any more

      
    // Set the callback timer to call this function again
      ISHELL_SetTimer( pApp->a.m_pIShell, BANNER_DISPLAY_TIMER, (PFNNOTIFY) XMR_PrinterTITLEAndContent, (void*) pApp );
     
       
    //ET_DisplayMainMenu( pApp );
       pApp->m_eAppState = APP_STATE_SPLASH;
    }


    ISHELL_SetTimer( pApp->a.m_pIShell, BANNER_DISPLAY_TIMER, (PFNNOTIFY) XMR_PrinterTITLEAndContent, (void*) pApp );
    ---等待一段时间后,调用XMR_PrinterTITLEAndContent。

    结构体代码:

    typedef enum
    {
      APP_STATE_SPLASH,
      APP_STATE_MAIN,
      APP_STATE_ADD,
      APP_STATE_VIEW,
      APP_STATE_VIEW_LIST,
      APP_STATE_EDIT,
      APP_STATE_OPTIONS,
      APP_STATE_LOAD_LIST,
      APP_STATE_REPORT,
      APP_STATE_SAVE_CONFIRM,
      APP_STATE_SAVE,
      APP_STATE_HELP,
      APP_STATE_ABOUT
    } EAppStateType;

    typedef 
    struct _hellobrew {
        AEEApplet      a ;           
    // First element of this structure must be AEEApplet
        AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
        IStatic *m_pIStat; 
        EAppStateType           m_eAppState;
        IMenuCtl
    *               m_pMenu;  
        AEERect                 m_rScreenRect;
        IImage
    *                 m_pTitleBarImg;
        EAppStateType           m_eAppState; 
    } hellobrew;



    3:显示菜单页面:
    结构体代码:

    #include "AEEMenu.h"
    #include 
    "AEEDate.h"
    #include 
    "AEEText.h"

    #include 
    "amountCtrl.h"


    typedef 
    enum
    {
      APP_STATE_SPLASH,
      APP_STATE_MAIN,
      APP_STATE_ADD,
      APP_STATE_VIEW,
      APP_STATE_VIEW_LIST,
      APP_STATE_EDIT,
      APP_STATE_OPTIONS,
      APP_STATE_LOAD_LIST,
      APP_STATE_REPORT,
      APP_STATE_SAVE_CONFIRM,
      APP_STATE_SAVE,
      APP_STATE_HELP,
      APP_STATE_ABOUT
    } EAppStateType;

    typedef 
    struct _hellobrew {
        AEEApplet                a ;           
    // First element of this structure must be AEEApplet
        AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
        IStatic *m_pIStat; 
        EAppStateType           m_eAppState;
        IMenuCtl
    *               m_pMenu;  
        AEERect                 m_rScreenRect;
        IImage
    *                 m_pTitleBarImg;
        CAmountCtl
    *             m_pAmount; 
        IMenuCtl
    *               m_pSK;          // Softkey Menu
        IMenuCtl*               m_pList;        // List Menu
        IDateCtl*               m_pDate;        // Used for creating saved Date strings.
        ITextCtl*               m_pText;    
    } hellobrew;

    // 居中显示图片,等待一段时间后,调用XMR_PrinterTITLEAndContent
    static void ET_DisplaySplashScreen(hellobrew * pApp);
    static boolean ET_InitAppData(hellobrew * pApp);

    // 打印标题和正文
    static void XMR_PrinterTITLEAndContent(hellobrew * pApp);

    // 设置菜单
    static void XMR_SetMenu(hellobrew * pApp);
    static void ET_Reset(hellobrew * pApp, boolean bShowTitleBar );

    static boolean XMR_CreateMainControls(hellobrew* pApp);


    结构体中用到的其他结构体的定义:amountCtrl.h

    // Control Structure
    typedef struct
    {
      uint32 m_nAmount;
      IStatic
    * m_pAmount;
      boolean m_bIsActive;
    } CAmountCtl;


    extern CAmountCtl* CAMOUNTCTL_CreateInstance(IShell* pIShell);

    CAMOUNTCTL_CreateInstance的实现:

    #include "AEEModGen.h"
    #include 
    "AEEStdLib.h"
    #include 
    "amountCtrl.h"

    extern CAmountCtl* CAMOUNTCTL_CreateInstance( IShell* pIShell )
    {
      CAmountCtl
    * pAmtCtl = MALLOC( sizeof( CAmountCtl ) );

      
    if!pAmtCtl )
        
    return NULL;
      
    else
      {
        pAmtCtl
    ->m_nAmount = 0;
        pAmtCtl
    ->m_bIsActive = FALSE;

        
    if( ISHELL_CreateInstance( pIShell, AEECLSID_STATIC, (void**)&pAmtCtl->m_pAmount ) != SUCCESS )
        {
          FREEIF( pAmtCtl );
          
    return NULL;
        }
        
    else
        {
          ISTATIC_SetProperties( pAmtCtl
    ->m_pAmount, ST_MIDDLETEXT );
        }
      }
      
    return pAmtCtl;
    }

    页面菜单代码:
    初始方法中添加的代码:

    static boolean ET_InitAppData(hellobrew * pApp)
    {
       AEEDeviceInfo
    * pDeviceInfo;

       
    if(!XMR_CreateMainControls(pApp))
          
    return FALSE;

       pDeviceInfo 
    = (AEEDeviceInfo*) MALLOC( sizeof( AEEDeviceInfo ) );
       ISHELL_GetDeviceInfo(pApp
    ->a.m_pIShell, pDeviceInfo );

       pApp
    ->m_rScreenRect.x = 0;
       pApp
    ->m_rScreenRect.y = 16;
       pApp
    ->m_rScreenRect.dx = pDeviceInfo->cxScreen;
       pApp
    ->m_rScreenRect.dy = pDeviceInfo->cyScreen - 16;
       
    return TRUE;
    }

    上面方法中新添加的代码是:
    if(!XMR_CreateMainControls(pApp))
          return FALSE;

    在进入菜单页面时,先重置页面:

    static void ET_Reset(hellobrew * pApp, boolean bShowTitleBar )
    {
       
    // Reset Menu Controls
       IMENUCTL_Reset(pApp->m_pMenu);
    }

    菜单页面实现代码:

    // 设置页面菜单
    static void XMR_SetMenu(hellobrew * pApp)
    {
         CtlAddItem ai;

         ET_Reset(pApp, TRUE);

         
    // main menu
         IMENUCTL_SetTitle( pApp->m_pMenu, EXPENSETRACKER_RES_FILE, IDS_MAIN_MENU, NULL);

           
    // Add Items in the Menu
           ai.pText = NULL;
           ai.pImage 
    = NULL;
           ai.pszResImage 
    = ai.pszResText = EXPENSETRACKER_RES_FILE;
           ai.wFont 
    = AEE_FONT_NORMAL;
           ai.dwData 
    = 0;

           
    // Add New
           ai.wText = IDC_ADD_NEW;
           ai.wImage 
    = IDB_ADD_NEW;
           ai.wItemID 
    = IDC_ADD_NEW;

           IMENUCTL_AddItemEx(pApp
    ->m_pMenu, &ai);

           
    // View
           ai.wText = IDC_VIEW;
           ai.wImage 
    = IDB_VIEW;
           ai.wItemID 
    = IDC_VIEW;

           IMENUCTL_AddItemEx(pApp
    ->m_pMenu, &ai);

           
    // Options
           ai.wText = IDC_OPTIONS;
           ai.wImage 
    = IDB_OPTIONS;
           ai.wItemID 
    = IDC_OPTIONS;

           IMENUCTL_AddItemEx(pApp
    ->m_pMenu, &ai);

           
    // Help
           ai.wText = IDC_HELP;
           ai.wImage 
    = IDB_HELP;
           ai.wItemID 
    = IDC_HELP;

           IMENUCTL_AddItemEx(pApp
    ->m_pMenu, &ai);

           
    // About
           ai.wText = IDC_ABOUT;
           ai.wImage 
    = IDB_ABOUT;
           ai.wItemID 
    = IDC_ABOUT;

           IMENUCTL_AddItemEx(pApp
    ->m_pMenu, &ai);

           IMENUCTL_SetRect( pApp
    ->m_pMenu, &pApp->m_rScreenRect );
           IMENUCTL_SetActive( pApp
    ->m_pMenu, TRUE );
           pApp
    ->m_eAppState = APP_STATE_MAIN;
    }


    static boolean XMR_CreateMainControls(hellobrew* pApp)
    {
       AEERect rc;
       AEEItemStyle rNormalStyle;
       AEEItemStyle rSelStyle;

       
    // Create the main application controls.
       if((ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_MENUCTL, (void**)(&pApp->m_pMenu)) != SUCCESS) ||
          (ISHELL_CreateInstance(pApp
    ->a.m_pIShell, AEECLSID_SOFTKEYCTL, (void**)(&pApp->m_pSK)) != SUCCESS) ||
          (ISHELL_CreateInstance(pApp
    ->a.m_pIShell, AEECLSID_DATECTL, (void**)(&pApp->m_pDate)) != SUCCESS) ||
          (ISHELL_CreateInstance(pApp
    ->a.m_pIShell, AEECLSID_LISTCTL, (void**)(&pApp->m_pList)) != SUCCESS) ||
          (ISHELL_CreateInstance(pApp
    ->a.m_pIShell, AEECLSID_TEXTCTL, (void**)(&pApp->m_pText)) != SUCCESS ))
          
    return FALSE;

      
    // Create the CAmountCtl control.
      if((pApp->m_pAmount = CAMOUNTCTL_CreateInstance(pApp->a.m_pIShell)) == NULL)
          
    return FALSE;

      
    // Let's reset text control size so on subsequent this won't misbehave by erasing screen
      SETAEERECT(&rc, 0000);
      ITEXTCTL_SetRect(pApp
    ->m_pText, &rc);

      
    // Set the style of the menu control so that all the icons are displayed as
      
    // transparent.  This is set based on the default menu styles.

      ISHELL_GetItemStyle( pApp
    ->a.m_pIShell, AEE_IT_MENU, &rNormalStyle, &rSelStyle );
      rNormalStyle.roImage 
    = AEE_RO_TRANSPARENT;
      rSelStyle.roImage 
    = AEE_RO_TRANSPARENT;
      IMENUCTL_SetStyle( pApp
    ->m_pMenu, &rNormalStyle, &rSelStyle );

      
    return TRUE;
    }

    4:添加Add New菜单的响应事件:
    首先是在hellobrew_HandleEvent方法中添加代码:

    if (IMENUCTL_HandleEvent(pMe->m_pMenu, eCode, wParam, dwParam))
          
    return TRUE;

    然后在hellobrew_HandleEvent方法中添加代码:

    // 判断是不是选择了添加菜单
            case EVT_COMMAND:  // Handle 'SELECT' button events
              switch(wParam)
              {
                  
    case IDC_ADD_NEW:  // User selected 'Add New' from the Main Menu
                     pMe->m_eAppState = APP_STATE_ADD;
                     XMR_DisplayAddScreen(pMe);
                     
    return TRUE;
              }

     用于调用XMR_DisplayAddScreen方法来画该功能中的画面。

    case EVT_COMMAND:响应OK键按下的代码。

    5:实现根据上下按钮选择菜单的功能:
    在hellobrew_HandleEvent方法中添加代码:

    case EVT_CTL_SEL_CHANGED:
              
    // If the expense list screen is showing and the user changes the selected
              
    // expense item in the menu control, get the description of the transaction
              
    // from the database and display it at the top of the screen.
              if (pMe->m_eAppState == APP_STATE_VIEW_LIST)
              {            
                 AECHAR psTitle[ MAX_DESC_SIZE 
    + 1 ];            
                 IMenuCtl 
    * pMenu = (IMenuCtl*)dwParam;
                 uint16 nRecordID 
    = IMENUCTL_GetSel(pMenu) - EXPENSE_LIST_ID;
                 XMR_GetExpenseItem( pMe, nRecordID, NULL, psTitle, NULL, NULL );         
                 IMENUCTL_SetTitle(pMenu, NULL, NULL, psTitle);
                 IMENUCTL_Redraw(pMenu);
                 
    return TRUE;
              }
              
    break;

    代码中调用了XMR_GetExpenseItem方法,添加XMR_GetExpenseItem方法:

    extern boolean XMR_GetExpenseItem( hellobrew* pApp, uint16 nRecordID, dword* pnDateTime, AECHAR* psDesc, unsigned char* pcType, dword* pnAmount )
    {
        IDBRecord
    * pRecord;
      
      
    // Get the record using the ID

      
    if(( pRecord = IDATABASE_GetRecordByID( pApp->m_pDatabase, nRecordID )) == NULL)
        
    return FALSE;

      
    // Extract each of the data values from the record and assogn to the output 
      
    // arguments

      XMR_ParseExpenseRecord( pRecord, pnDateTime, pcType, psDesc, pnAmount );

      
    // Release the record

      IDBRECORD_Release( pRecord );

      
    return TRUE;
    }

    因为有pApp->m_pDatabase的调用,所以需要在_hellobrew结构体中添加变量:
    IDatabase*              m_pDatabase;
    IDatabase类型存在文件AEEDB.h。
    在XMR_GetExpenseItem方法中调用了XMR_ParseExpenseRecord方法。
    XMR_ParseExpenseRecord代码:
    static boolean XMR_ParseExpenseRecord( IDBRecord* pRecord, dword* pnDateTime, unsigned char* pcType, AECHAR* psDesc, dword* pnAmount )
    {
      uint16 nFieldLen;
      AEEDBFieldName rFieldName;
      AEEDBFieldType rFieldType;
      AECHAR
    * psStringPtr;

      IDBRECORD_Reset( pRecord );  
    // Set the record index to -1
      
      
    // Get the first field

      rFieldType 
    = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen );

      
    // Set the DateTime if pnDateTime is a valid pointer

      
    if( pnDateTime )
        IDBRECORD_GetFieldDWord( pRecord, pnDateTime );
      
      
    // Get next field

      rFieldType 
    = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen );

      
    // Set the description if psDesc is a valid pointer

      
    if( psDesc )
      {
        psStringPtr 
    = IDBRECORD_GetFieldString( pRecord );
        WSTRCPY( psDesc, psStringPtr );

        
    // psStringPtr is not freed by us because the pointer is owned by the
        
    // IDBRecord (See API Reference for IDBRECORD_GetFieldString ).
      }

      
    // Get next field

      rFieldType 
    = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen );

      
    // Set the transaction type if pcType is a valid pointer

      
    if( pcType )
        
    *pcType = *IDBRECORD_GetField( pRecord, &rFieldName, &rFieldType, &nFieldLen );
      
      
    // Get next field

      rFieldType 
    = IDBRECORD_NextField( pRecord, &rFieldName, &nFieldLen );

      
    // Set the amount if pnAmount is a valid pointer

      
    if( pnAmount )
        IDBRECORD_GetFieldDWord( pRecord, pnAmount );
      
      
    return TRUE;
    }
  • 相关阅读:
    Callable和Future 多线程
    【spring-boot】spring-boot 整合 ehcache 实现缓存机制
    java 设计模式http://www.runoob.com/design-pattern/design-pattern-tutorial.html
    DDD领域驱动设计(例子)
    js要怎么接收后端传的excel文件流?
    构建最小JDK Docker镜像 或者直接使用镜像:frolvlad/alpine-oraclejre8:slim
    JVM知识点总结
    DDD随笔-Axon
    HttpServletRequest  通用的post 请求
    List转数组
  • 原文地址:https://www.cnblogs.com/admin11/p/975224.html
Copyright © 2011-2022 走看看