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

📄 string.c

📁 brew中字符串的操作
💻 C
字号:
/*===========================================================================

FILE: string.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "aeemenu.h"
#include "AEEStdlib.h"
#include "string.h"
#include "string.bid"
#include "string_res.h"
#define STATE_MAINMENU 1
#define kColorClearGray 0xC0C0C000
#define kColorClearLightYellow 0xC0FFFF00
#define kColorClearBlack 0X000000000
#define kColorClearDialogBox kColorClearBlack
#define kColorClearDialogBackGround kColorClearLightYellow
#define DIALOG_BORDER_WIDTH 1//对话框边的宽度

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
typedef struct STRUCT_STRING
{
	AEEApplet app;
	IMenuCtl *pMenuCtl;
	int m_nScrWidth;
	int m_nScrHeight;
	int m_nLineHeight;
    int m_nLargeLineHeight;
	AEERect m_nClntAreaRect;
	uint8 m_nState;
   	AECHAR buffer[20];
	AECHAR buffer1[20];
	AECHAR buffer2[20];
}STring;
static boolean string_HandleEvent(STring*,AEEEvent,uint16,uint32);
static boolean string_InitAppData(STring *);
static void string_FreeAppData(STring *);
static void DevDrawDialog(STring *pApp,const AECHAR *szText);
static boolean string_Start(STring * pApp);

//static boolean string_HandleEvent(IApplet * pi, AEEEvent eCode, 
//                                      uint16 wParam, uint32 dwParam);

/*===============================================================================
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)
{
	STring *pApp;
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_STRING){
      if(AEEApplet_New(sizeof(STring), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)string_HandleEvent,(PFNFREEAPPDATA)string_FreeAppData)
         == TRUE)
      {
		pApp=(STring *)*ppObj;
		if(!string_InitAppData(pApp))
		{
			IAPPLET_Release((IApplet *)pApp);
			*ppObj=NULL;
			return EFAILED;
		}

         return (AEE_SUCCESS);
      }
   }
	return (EFAILED);
}

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

FUNCTION string_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 string_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 string_HandleEvent(STring *pApp, AEEEvent eCode, uint16 w, uint32 dw)
{  
	AECHAR format[]={'%','s','%','s',0};
    AECHAR bf='o';
	AECHAR *pCh;
	int cmp;
	int nRem;
   switch (eCode) 
	{
      case EVT_APP_START:                        
		   return string_Start(pApp);
		   
      case EVT_APP_STOP:
		  return TRUE;
	  case EVT_KEY:
		  switch(pApp->m_nState)
		  {
		  case STATE_MAINMENU:
			 return IMENUCTL_HandleEvent(pApp->pMenuCtl,EVT_KEY,w,dw);
           default:
				  return FALSE;
		  }
		  case EVT_COMMAND:
			  switch(w) 
			  {
			     case IDS_INIT:
					  string_Start(pApp);
                      ISHELL_LoadResString(pApp->app.m_pIShell,STRING_RES_FILE,IDS_STR1,pApp->buffer1,sizeof(pApp->buffer1));
                      ISHELL_LoadResString(pApp->app.m_pIShell,STRING_RES_FILE,IDS_STR2,pApp->buffer2,sizeof(pApp->buffer2));                     
                      return TRUE;
                 case IDS_STRCAT:
					 WSTRCAT(pApp->buffer1,pApp->buffer2);
                     DevDrawDialog(pApp,(const AECHAR *)pApp->buffer1);
					 return TRUE;
				 case IDS_STRLCAT:
					 WSTRLCAT(pApp->buffer1,pApp->buffer2,sizeof(pApp->buffer1));
                     DevDrawDialog(pApp,(const AECHAR *)pApp->buffer1);
					 return TRUE;
				 case IDS_FMAT:
					 WSPRINTF(pApp->buffer,sizeof(pApp->buffer),format,pApp->buffer1,pApp->buffer2);
                      DevDrawDialog(pApp,(const AECHAR *)pApp->buffer);
					 return TRUE;
                 case IDS_SECH:
				      pCh=WSTRCHR(pApp->buffer1,bf);
                      DevDrawDialog(pApp,(const AECHAR *)pCh);
					  return TRUE;
				 case IDS_RSECH:
				      pCh=WSTRCHR(pApp->buffer1,bf);
                      DevDrawDialog(pApp,(const AECHAR *)pCh);
					  return TRUE;
                 case IDS_CMP:
					 cmp=WSTRCMP(pApp->buffer1,pApp->buffer2);
					 WWRITELONG(pApp->buffer,(long)cmp);
                     DevDrawDialog(pApp,(const AECHAR *)pApp->buffer);
					 return TRUE;
			  	 case IDS_NCMP:
					 
					 cmp=WSTRNCMP(pApp->buffer1,pApp->buffer2,sizeof(pApp->buffer1));//sizeof(pApp->buffer1)
					 nRem=sizeof(pApp->buffer)/sizeof(AECHAR);
					 WWRITELONGEX(pApp->buffer,(long)cmp,2,&nRem);
                     DevDrawDialog(pApp,(const AECHAR *)pApp->buffer);
					 return TRUE;
			  default:
				  break;
			  }

      default:
         break;
   }
   return FALSE;
}
/*=============================================================================*/
static boolean string_InitAppData(STring *pApp)
{
	AEEDeviceInfo deviceInfo;

    if(ISHELL_CreateInstance(pApp->app.m_pIShell,AEECLSID_MENUCTL,
		(void **)&pApp->pMenuCtl)!=SUCCESS)      //创建标准菜单接口

		return FALSE;
   ISHELL_GetDeviceInfo(pApp->app.m_pIShell,&deviceInfo);
    pApp->m_nLineHeight = IDISPLAY_GetFontMetrics(pApp->app.m_pIDisplay,
											      AEE_FONT_NORMAL,
											      NULL,
											      NULL);//常用字体的高度
    pApp->m_nLargeLineHeight= IDISPLAY_GetFontMetrics(pApp->app.m_pIDisplay,
												  AEE_FONT_LARGE,
												  NULL,
												  NULL);//LARGE字体的高度
    pApp->m_nScrHeight = deviceInfo.cyScreen;              //屏幕高度
    pApp->m_nScrWidth = deviceInfo.cxScreen;               //屏幕宽度
    SETAEERECT(&pApp->m_nClntAreaRect,
		   0,
		   0,
		   deviceInfo.cxScreen,
		   deviceInfo.cyScreen-pApp->m_nLargeLineHeight);
          
		   return TRUE;
}
/*===========================================================================*/
static void string_FreeAppData(STring * pApp)
{
	if(pApp->pMenuCtl)
	{
		IMENUCTL_Release(pApp->pMenuCtl);
		pApp->pMenuCtl=NULL;
	}

}
/*===========================================================================*/
static boolean string_Start(STring * pApp)
{
	CtlAddItem rMenuItem;      //定义可包含图标的菜单项
	AEERect nRect;             //矩形变量 
	AEEItemStyle nNormal;      //定义菜单的样式变量
	AEEItemStyle nSel;
	IMENUCTL_Reset(pApp->pMenuCtl);              //指定菜单控件?
	IMENUCTL_SetActive(pApp->pMenuCtl,FALSE);    //将菜单控件设置为非活动中?
	rMenuItem.pText = NULL;
	rMenuItem.pImage = NULL;                     //若不用一定要赋予空
	rMenuItem.pszResImage = rMenuItem.pszResText = STRING_RES_FILE;//将图像和文本资源指向资源文件
	/* 设定菜单选项,并添加菜单*/
	IMENUCTL_SetTitle(pApp->pMenuCtl,STRING_RES_FILE,IDS_TITLE,NULL);
	rMenuItem.wFont = AEE_FONT_NORMAL;                      
	rMenuItem.wText = IDS_INIT;
	rMenuItem.wImage = IDB_IMAGE;
	rMenuItem.wItemID = IDS_INIT;                            //设置菜单项的ID,必须唯一
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);             //添加菜单项
	rMenuItem.wFont = AEE_FONT_NORMAL;                      
	rMenuItem.wText = IDS_STRCAT;
	rMenuItem.wImage = IDB_IMAGE;
	rMenuItem.wItemID = IDS_STRCAT;                           
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
	rMenuItem.wText = IDS_STRLCAT;
	rMenuItem.wImage = IDB_IMAGE;
	rMenuItem.wItemID = IDS_STRLCAT;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
	rMenuItem.wText = IDS_FMAT;
	rMenuItem.wImage = IDB_IMAGE;
	rMenuItem.wItemID = IDS_FMAT;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
	rMenuItem.wText=IDS_SECH;
	rMenuItem.wImage=IDB_IMAGE;
	rMenuItem.wItemID=IDS_SECH;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
    rMenuItem.wText=IDS_RSECH;
	rMenuItem.wImage=IDB_IMAGE;
	rMenuItem.wItemID=IDS_RSECH;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
	rMenuItem.wText=IDS_CMP;
	rMenuItem.wImage=IDB_IMAGE;
	rMenuItem.wItemID=IDS_CMP;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
	rMenuItem.wText=IDS_NCMP;
	rMenuItem.wImage=IDB_IMAGE;
	rMenuItem.wItemID=IDS_NCMP;
	IMENUCTL_AddItemEx(pApp->pMenuCtl,&rMenuItem);
    nNormal.ft = AEE_FT_NONE;
	nNormal.xOffset = nNormal.yOffset =0;
	nNormal.roImage = AEE_RO_TRANSPARENT;
	nSel.ft = AEE_FT_RAISED;
	nSel.xOffset = nSel.yOffset = 0;
	nSel.roImage =AEE_RO_TRANSPARENT;
	IMENUCTL_SetStyle(pApp->pMenuCtl,&nNormal,&nSel);            //设置菜单在正常和被选择情况下的状态
    IMENUCTL_SetProperties( pApp->pMenuCtl,IMENUCTL_GetProperties( pApp->pMenuCtl )&~(MP_ICON_TEXT_TOP) );//设置菜单控件的属性
    SETAEERECT( &nRect, 0, 0, pApp->m_nScrWidth, pApp->m_nScrHeight );
    IMENUCTL_SetRect( pApp->pMenuCtl, &nRect );                 //绘制菜单的范围
    IMENUCTL_SetActive( pApp->pMenuCtl, TRUE );                 //将菜单设置为活动状态
    pApp->m_nState = STATE_MAINMENU;      
    return TRUE;
}
/*====================================================================================*/
static void DevDrawDialog(STring * pApp,const AECHAR *szText)
{
    const AECHAR *p;
    AEERect nRect;
    int nFits = 0;
    int width = 0;                                           //实际的像素宽度
    int height = pApp->m_nLineHeight;
    int length = 0;	
    int max_width = pApp->m_nClntAreaRect.dx - 10;    
    p = szText;
    while(*p)
    {
        width = IDISPLAY_MeasureTextEx(pApp->app.m_pIDisplay,
            AEE_FONT_NORMAL,
        	p,
        	-1,
            max_width,
            &nFits);
       height += pApp->m_nLineHeight;
        p+=nFits;
    }
     if(height > pApp->m_nLineHeight + pApp->m_nLineHeight)//文本内容多于一行时
       width = max_width;
    SETAEERECT(&nRect,(pApp->m_nClntAreaRect.dx-width)/2-DIALOG_BORDER_WIDTH,(pApp->m_nClntAreaRect.dy-height)/2,width+DIALOG_BORDER_WIDTH,height);
    IDISPLAY_DrawRect(pApp->app.m_pIDisplay,&nRect,kColorClearDialogBox,kColorClearDialogBackGround,IDF_RECT_FRAME|IDF_RECT_FILL);
    /* 绘制文本*/
    nRect.x += DIALOG_BORDER_WIDTH;                        //加上对话框的宽度
    nRect.dx -= DIALOG_BORDER_WIDTH;
    p = szText;
    height = nRect.y+pApp->m_nLineHeight/2;
    while(*p)
    {
        width = IDISPLAY_MeasureTextEx(pApp->app.m_pIDisplay,
            AEE_FONT_NORMAL,
        	p,
        	-1,
           max_width,
            &nFits);
        IDISPLAY_DrawText(pApp->app.m_pIDisplay,
            AEE_FONT_NORMAL,
        	p,
           nFits,
            nRect.x,
            height,
            &nRect,
            IDF_TEXT_TRANSPARENT);
        p+=nFits;
        height +=pApp->m_nLineHeight;
    }
    IDISPLAY_Update(pApp->app.m_pIDisplay);
}

⌨️ 快捷键说明

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