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

📄 idialog.c

📁 通过事例来详细介绍iDIolog接口的应用,具有实战性,适合初学者.
💻 C
字号:
/*===========================================================================

FILE: idialog.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEText.h"
#include "idialog.bid"
#include "idialog_res.h"
#define DIALOG_BORDER_WIDTH 1
typedef struct _IDLOGTEXT
{
	AEEApplet app;
	ITextCtl *pTextCtl;
	IDialog *pIDialog;
	AEEDeviceInfo deviceInfo;
	int m_nScrWidth;
	int m_nScrHeight;
	int m_nLineHeight;
    int m_nLargeLineHeight;
	AEERect m_nClntAreaRect;
//	uint8  m_nState;

}IDilog;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean idialog_HandleEvent(IDilog * , AEEEvent eCode, 
                                      uint16 w, uint32 dw);
static boolean idialog_initAppData(IDilog *pApp);
static void idialog_freeAppData(IDilog *pApp);
static void idialog_start(IDilog *pApp);
static void DevDrawDialog(IDilog * pApp,const AECHAR *szText);

/*===============================================================================
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)
{ 
	IDilog *pApp;
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_IDIALOG){
      if(AEEApplet_New(sizeof(IDilog), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)idialog_HandleEvent,(PFNFREEAPPDATA)idialog_freeAppData)
         == TRUE)
      {
		 pApp=(IDilog *)*ppObj;
		 if(!idialog_initAppData(pApp))
		 {
			 IAPPLET_Release((IApplet *)pApp);			 
			 *ppObj=NULL;
			 return EFAILED;
		 }

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

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

FUNCTION idialog_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 idialog_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 idialog_HandleEvent(IDilog * pApp, AEEEvent eCode, uint16 w, uint32 dw)
{ 
    //int res;
    AEERect rect;
    AECHAR  szText[60];
		if (pApp->pTextCtl)
		{
	      ITEXTCTL_HandleEvent(pApp->pTextCtl,eCode,w,dw);	
		}
   switch (eCode) 
	{
      case EVT_APP_START:                        
		    ISHELL_CreateDialog(pApp->app.m_pIShell,IDIALOG_RES_FILE,IDD_DIALOG_TEXT,NULL);		            
      		return(TRUE);
      case EVT_APP_STOP:

		    // Add your code here .....

         return TRUE;
	  case EVT_KEY:

	      switch(w)
		  {
		  case AVK_SELECT:
               ISHELL_EndDialog(pApp->app.m_pIShell);
	    	   return TRUE;
		   default :
			   return FALSE;
		  }
	case EVT_DIALOG_INIT:
		 //res=ISHELL_CreateDialog(pApp->app.m_pIShell,IDIALOG_RES_FILE,IDD_DIALOG_TEXT,NULL);
		 return TRUE;
	 case EVT_DIALOG_START:
		 pApp->pIDialog=ISHELL_GetActiveDialog(pApp->app.m_pIShell);
		 IDIALOG_SetFocus(pApp->pIDialog,IDD_STATIC_DIALOG);
         pApp->pTextCtl=(ITextCtl *)IDIALOG_GetControl(pApp->pIDialog,IDD_STATIC_DIALOG);
            SETAEERECT(&rect,10,10,80,80);
		    ITEXTCTL_SetProperties(pApp->pTextCtl,TP_FRAME|TP_MULTILINE);//设置有边框
	        ITEXTCTL_SetRect(pApp->pTextCtl,&rect);//设置写入的文本矩形框
         	ITEXTCTL_SetMaxSize(pApp->pTextCtl,30);//设置要输入的文本框中内容的字符数
            ITEXTCTL_SetInputMode(pApp->pTextCtl,AEE_TM_NUMBERS);//设置输入类型		            
		
		  IDIALOG_Redraw(pApp->pIDialog);
		   
          return TRUE;
	  case EVT_DIALOG_END:
		  IDISPLAY_ClearScreen(pApp->app.m_pIDisplay);
		  ITEXTCTL_GetText(pApp->pTextCtl,szText,30);
		  DevDrawDialog(pApp,(const AECHAR *)szText);
		  IDISPLAY_Update(pApp->app.m_pIDisplay);

		  return TRUE;
         
      default:
         break;
   }
   return FALSE;
}
/*=========================================================================================*/
static boolean idialog_initAppData(IDilog *pApp)
{
	if(ISHELL_CreateInstance(pApp->app.m_pIShell,AEECLSID_TEXTCTL,&pApp->pTextCtl)!=SUCCESS)
		return FALSE;
	ISHELL_GetDeviceInfo(pApp->app.m_pIShell,&pApp->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 = pApp->deviceInfo.cyScreen;              //屏幕高度
   pApp->m_nScrWidth = pApp->deviceInfo.cxScreen;               //屏幕宽度
   SETAEERECT(&pApp->m_nClntAreaRect,
		   0,
		   0,
		   pApp->deviceInfo.cxScreen,
		   pApp->deviceInfo.cyScreen-pApp->m_nLargeLineHeight);
          
	return TRUE;

}
static void idialog_freeAppData(IDilog *pApp)
{
	if(pApp->pTextCtl)
	{
		ITEXTCTL_Release(pApp->pTextCtl);
		pApp->pTextCtl=NULL;
	}
	//ISHELL_EndDialog(pApp->pIDialog);
}
/*static void idialog_start(IDilog *pApp)
{
  int res;
   res=ISHELL_CreateDialog(pApp->app.m_pIShell,IDIALOG_RES_FILE,IDD_DIALOG_TEXT,NULL);
   pApp->pIDialog=ISHELL_GetActiveDialog(pApp->app.m_pIShell);
  IDIALOG_SetFocus(pApp->pIDialog,IDD_STATIC_DIALOG);
  pApp->pTextCtl=(ITextCtl *)IDIALOG_GetControl(pApp->pIDialog,IDD_STATIC_DIALOG);
		 //ITEXTCTL_SetActive(pApp->pITextCtl,TRUE);//激活文本菜单
  // ISHELL_EndDialog(pApp->pIDialog);
  
}
static void itext_start(IDilog *pApp)
{

	SETAEERECT(&pApp->rect,0,0,100,50);//设置矩形大小
	ITEXTCTL_SetProperties(pApp->pITextCtl,TP_FRAME);//设置有边框
	//ITEXTCTL_SetTitle(pApp->pITextCtl,ITEXT_RES_FILE,IDS_TITLE,NULL);//设置文本输入框的标题
	ITEXTCTL_SetRect(pApp->pITextCtl,&pApp->rect);//设置写入的文本矩形框
	ITEXTCTL_SetMaxSize(pApp->pITextCtl,15);//设置要输入的文本框中内容的字符数
	ITEXTCTL_SetInputMode(pApp->pITextCtl,AEE_TM_NUMBERS);//设置输入类型
	ITEXTCTL_SetActive(pApp->pITextCtl,TRUE);//激活文本菜单	
}
*/
static void DevDrawDialog(IDilog * 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,0xffffff00,0xffffff00,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 + -