急求一个ITextCtl的例子!!!!!!!!!!!!!

cancer0713 2008-05-22 11:19:01
刚开始接触BREW,想作一个简单的练习,界面:有两个输入框,用上下键可以进行切换;一个SAVE键,用来保存在输入框中输入的内容。谁能提供点关于如何创建ITEXTCTL的例子啊?API上面看了半天也没看懂,实在是不好意思啊!
...全文
1266 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
visual4825 2009-03-21
  • 打赏
  • 举报
回复
>还有个问题。是关于如何进行文件操作的。比如我分别在两个输入框中输入了信息。
>要对其进行保存,使下次进入时在输入框中显示的是保存的内容!请问该如何处理啊?

写NV
韩明君 2009-03-05
  • 打赏
  • 举报
回复
学习学习!!
yuhan20030307 2008-07-29
  • 打赏
  • 举报
回复
学习中
炽天使_1985 2008-07-21
  • 打赏
  • 举报
回复

TextDemo_res.h 文件


#ifndef TEXTDEMO_RES_H
#define TEXTDEMO_RES_H

// WARNING: DO NOT MODIFY THIS FILE
// AUTO-GENERATED BY BREW Resource Editor

#define TEXTDEMO_RES_FILE "TextDemo.bar"

#define IDS_SOFT_1 1
#define IDS_SOFT_2 2
#define IDS_TEXT_TITLE 4
#define YP 5001


#endif // TEXTDEMO_RES_H
....................................................................
TextDemo.h 头文件

#ifndef _TEXT_DEMO_H_
#define _TEXT_DEMO_H_

typedef struct _TextDemo
{
AEEApplet a;
ITextCtl *pText;
}TextDemo;

#endif






.............................................................................................


#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEText.h"
#include "TextDemo.bid"
#include "TextDemo.h"
#include "TextDemo_res.h"

#define MAX_BUF_SIZE 15

static boolean TextDemo_HandleEvent(IApplet * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean TextDemo_InitAppData(TextDemo *pThis);
static void TextDemo_FreeAppData(TextDemo *pThis);

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

if(ClsId == AEECLSID_TEXTDEMO){
if(AEEApplet_New(sizeof(TextDemo), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)TextDemo_HandleEvent,(PFNFREEAPPDATA)TextDemo_FreeAppData)
== TRUE)
{
// Add your code here .....
if( TextDemo_InitAppData((TextDemo *)(*ppObj)) )
{
return (AEE_SUCCESS);
}
else
{
IAPPLET_Release((IApplet *)(*ppObj));
return (EFAILED);
}
}
}
return (EFAILED);
}


static boolean TextDemo_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
TextDemo *pThis = (TextDemo *)pi;
AEERect rect = {0, 0, 100, 50};
AECHAR buffer[MAX_BUF_SIZE+1];
switch (eCode)
{
case EVT_APP_START:

// Add your code here .....
ISHELL_CreateInstance(pThis->a.m_pIShell, AEECLSID_TEXTCTL, (void **)&pThis->pText);
ITEXTCTL_SetProperties(pThis->pText, TP_FRAME);
ITEXTCTL_SetTitle(pThis->pText, TEXTDEMO_RES_FILE, IDS_TEXT_TITLE, NULL);
ITEXTCTL_SetRect(pThis->pText, &rect);
ITEXTCTL_SetMaxSize(pThis->pText, MAX_BUF_SIZE);
ITEXTCTL_SetInputMode(pThis->pText, AEE_TM_NUMBERS);
ITEXTCTL_SetActive(pThis->pText, TRUE);
return(TRUE);
case EVT_KEY:
if(AVK_SELECT == wParam)
{
ITEXTCTL_GetText(pThis->pText, buffer, MAX_BUF_SIZE);
IDISPLAY_DrawText(pThis->a.m_pIDisplay, AEE_FONT_NORMAL, buffer, -1, 0, 0, NULL, IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);
IDISPLAY_Update(pThis->a.m_pIDisplay);
return TRUE;
}
if(pThis->pText)
{
ITEXTCTL_HandleEvent(pThis->pText, eCode, wParam, dwParam);
return TRUE;
}
return FALSE;
case EVT_APP_STOP:

// Add your code here .....

return TRUE;
case EVT_APP_SUSPEND:
if(pThis->pText)
{
ITEXTCTL_SetActive(pThis->pText, FALSE);
}
return TRUE;
case EVT_APP_RESUME:
if(pThis->pText)
{
ITEXTCTL_SetActive(pThis->pText, TRUE);
}
return TRUE;
default:
break;
}
return FALSE;
}

static boolean TextDemo_InitAppData(TextDemo *pThis)
{
pThis->pText = NULL;
return TRUE;
}

static void TextDemo_FreeAppData(TextDemo *pThis)
{
if(pThis->pText)
{
ITEXTCTL_Release(pThis->pText);
pThis->pText = NULL;
}
}
Daemon_neu 2008-05-26
  • 打赏
  • 举报
回复
/*===========================================================================

FILE: FileSample.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions

#include "filesample.bid"

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean FileSample_HandleEvent(IApplet * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
static boolean FileSample_TestFun(IShell *pIShell, uint32 score);

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

if(ClsId == AEECLSID_FILESAMPLE){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)FileSample_HandleEvent,NULL)
== TRUE)
{
// Add your code here .....

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

static boolean FileSample_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
AECHAR hints1[18] = {'P','r','e','s','s',' ','S','E','L',' ','t','o',' ','t','e','s','t','!'};
AECHAR hints2[13] = {'T','e','s','t',' ','S','u','c','c','e','s','s','!'};
AECHAR hints3[12] = {'T','e','s','t',' ','F','a','i','l','e','d','!'};

AEEApplet *pAEEApplet = (AEEApplet *)pi;
IDisplay *pIDisplay = pAEEApplet->m_pIDisplay;
IShell *pIShell = pAEEApplet->m_pIShell;

switch (eCode)
{
case EVT_APP_START:
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints1,
18, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
// Add your code here .....

return(TRUE);
case EVT_APP_STOP:

// Add your code here .....

return TRUE;
case EVT_KEY:
switch(wParam)
{
case AVK_SELECT:
if(FileSample_TestFun(pIShell, 50) == SUCCESS){
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints2,
13, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
}
else{
IDISPLAY_ClearScreen(pIDisplay);
IDISPLAY_DrawText(pIDisplay, AEE_FONT_NORMAL, hints3,
12, 0, 50, NULL, IDF_ALIGN_CENTER);
IDISPLAY_Update(pIDisplay);
}
return TRUE;
default:
break;
}
default:
break;
}
return FALSE;
}


static boolean FileSample_TestFun(IShell *pIShell, uint32 score)
{

const char *pszfile = "record.dat";


uint32 oldscore = 0;


IFileMgr *pIFileMgr = NULL;


IFile *pIFile = NULL;
int i;


if(ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS){
return EFAILED;
}


if(IFILEMGR_Test(pIFileMgr, pszfile) == SUCCESS){

if((pIFile = IFILEMGR_OpenFile(pIFileMgr, pszfile, _OFM_READWRITE)) == NULL){
return EFAILED;
}

i= IFILE_Seek(pIFile, _SEEK_START, 0);
i=IFILE_Write(pIFile, &score, sizeof(uint32));
i=IFILE_Read(pIFile, &oldscore, sizeof(uint32));


if(score > oldscore){

i= IFILE_Seek(pIFile, _SEEK_START, 0);

i= IFILE_Write(pIFile, &score, sizeof(uint32));
}
}
else{

if((pIFile = IFILEMGR_OpenFile(pIFileMgr, pszfile, _OFM_CREATE)) == NULL){
return EFAILED;
}


i=IFILE_Write(pIFile, &score, sizeof(uint32));
}


IFILE_Release(pIFile);


IFILEMGR_Release(pIFileMgr);

return SUCCESS;
}


cancer0713 2008-05-24
  • 打赏
  • 举报
回复
恩 谢谢 我试试!
还有个问题。是关于如何进行文件操作的。比如我分别在两个输入框中输入了信息。要对其进行保存,使下次进入时在输入框中显示的是保存的内容!请问该如何处理啊?
Daemon_neu 2008-05-24
  • 打赏
  • 举报
回复
基于dialog的文本框输入
试试吧
Daemon_neu 2008-05-24
  • 打赏
  • 举报
回复
static boolean DialogApp_HandleEvent(DialogApp* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{

int nRet;
const AECHAR dlgCaption[]={'D','i','a','l','o','g',' ','D','e','m','o','\0'};
const AECHAR dlgText[] = {'T','h','i','s',' ','a',' ','D','i','a','l','o','g','\0'};
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
// Add your code here...

if(SUCCESS == (nRet=ISHELL_CreateDialog(pMe->a.m_pIShell, DIALOG_RES_FILE,
IDD_DEMODLG, NULL)))
return TRUE;
else
return FALSE;

// 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...


// App is being resumed
case EVT_APP_RESUME:
// Add your code here...


// 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...



// 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...

switch(eCode)
{
case AVK_SELECT:
ISHELL_EndDialog(pMe->a.m_pIShell);
return TRUE;
}
return FALSE;
case EVT_DIALOG_INIT:
pMe->m_pDialog = (IDialog*)dwParam;
IDIALOG_SetEventHandler(pMe->m_pDialog, (PFNAEEEVENT)dlg_HandleEvent, (void* )pMe);
return(TRUE);

case EVT_DIALOG_START:
case EVT_DIALOG_END:

return TRUE;
case EVT_COMMAND:

return TRUE;

// 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 DialogApp_InitAppData(DialogApp* pMe)
{
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);

// Insert your code here for initializing or allocating resources...

pMe->m_nLineHeight = IDISPLAY_GetFontMetrics(pMe->a.m_pIDisplay,
AEE_FONT_NORMAL,
NULL,
NULL);
pMe->m_nLargeLineHeight = IDISPLAY_GetFontMetrics(pMe->a.m_pIDisplay,
AEE_FONT_LARGE,
NULL,
NULL);

pMe->m_nScrHeight = pMe->DeviceInfo.cyScreen;
pMe->m_nScrWidth = pMe->DeviceInfo.cxScreen;

SETAEERECT(&pMe->m_nClntAreaRect,
0,
0,
pMe->DeviceInfo.cxScreen,
pMe->DeviceInfo.cyScreen-pMe->m_nLargeLineHeight);


// if there have been no failures up to this point then return success
return TRUE;
}

// this function is called when your application is exiting
void DialogApp_FreeAppData(DialogApp* pMe)
{
// insert your code here for freeing any resources you have allocated...

// example to use for releasing each interface:
// if ( pMe->pIMenuCtl != NULL ) // check for NULL first
// {
// IMENUCTL_Release(pMe->pIMenuCtl) // release the interface
// pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
// }
//

}
static void dialog_ReleaseObj(void ** ppObj)
{
if ( ppObj && *ppObj )
{
(void) IBASE_Release( ( (IBase *) *ppObj ) );
*ppObj = NULL;
}
}

static boolean dlg_HandleEvent(DialogApp * pMe, AEEEvent evt, uint16 w, uint32 dw)
{
ITextCtl *pITextCtl;
AEERect rc;
AECHAR pBuf[60];
AECHAR *p;
int nFits = 0;
int width = 0;
int height = pMe->m_nLineHeight;
#define EDIT_WIDTH 80
#define EDIT_HEIGHT 80
switch (evt)
{

case EVT_DIALOG_START:

pITextCtl = (ITextCtl *)IDIALOG_GetControl(pMe->m_pDialog,IDC_DLGTEXT);
SETAEERECT( &rc, (pMe->m_nScrWidth-EDIT_WIDTH)/2,(pMe->m_nScrHeight-EDIT_HEIGHT)/2, EDIT_WIDTH, EDIT_HEIGHT);
ITEXTCTL_SetRect(pITextCtl, &rc);
ITEXTCTL_SetMaxSize(pITextCtl, 80);
ITEXTCTL_SetProperties(pITextCtl,TP_FRAME|TP_MULTILINE);
rc.x-=2; rc.dx +=4; rc.y -=2;rc.dy +=6;

IDISPLAY_DrawRect(pMe->a.m_pIDisplay,&rc,kColorClearDialogBox,kColorClearDialogBackground,IDF_RECT_FRAME|IDF_RECT_FILL);

ITEXTCTL_Redraw(pITextCtl);

return TRUE;
case EVT_DIALOG_END:
pITextCtl = (ITextCtl *)IDIALOG_GetControl(pMe->m_pDialog,IDC_DLGTEXT);
ITEXTCTL_GetText(pITextCtl,
pBuf,
sizeof(pBuf));
p = pBuf;
IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
while(*p)
{
IDISPLAY_MeasureTextEx(pMe->a.m_pIDisplay,
AEE_FONT_NORMAL,
p,
-1,
pMe->m_nScrWidth,
&nFits);


IDISPLAY_DrawText(pMe->a.m_pIDisplay,
AEE_FONT_NORMAL,
p,
nFits,
0,
height,
NULL,
IDF_TEXT_UNDERLINE);
p+=nFits;
height +=pMe->m_nLineHeight;

}
IDISPLAY_Update(pMe->a.m_pIDisplay);

return TRUE;
case EVT_KEY:
return FALSE;
case EVT_COMMAND:
return FALSE;
default:
return FALSE;
}
}
Daemon_neu 2008-05-24
  • 打赏
  • 举报
回复
/*===========================================================================

FILE: DialogApp.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions

#include "DialogApp.bid"
#include "AEEStdLib.h"

#include "aeemenu.h"
#include "dialog_res.brh"
#include "aeetext.h"


#define kColorClearGray 0xC0C0C000
#define kColorClearLightYellow 0xC0FFFF00
#define kColorClearBlack 0x00000000
#define kColorClearDialogBox kColorClearBlack
#define kColorClearDialogBackground kColorClearLightYellow


/*-------------------------------------------------------------------
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 _DialogApp {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information

// add your own variables here...
int m_nScrWidth;
int m_nScrHeight;
int m_nLineHeight; // normal font
int m_nLargeLineHeight; //large font
AEERect m_nClntAreaRect;
IDialog *m_pDialog;

} DialogApp;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean DialogApp_HandleEvent(DialogApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean DialogApp_InitAppData(DialogApp* pMe);
void DialogApp_FreeAppData(DialogApp* pMe);
static void dialog_ReleaseObj(void ** ppObj);
static boolean dlg_HandleEvent(DialogApp * pMe, AEEEvent evt, uint16 w, uint32 dw);
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;

if( ClsId == AEECLSID_DIALOGAPP )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(DialogApp),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)DialogApp_HandleEvent,
(PFNFREEAPPDATA)DialogApp_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(DialogApp_InitAppData((DialogApp*)*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);
}

975

社区成员

发帖
与我相关
我的任务
社区描述
本论坛以AI、WoS 、XR、IoT、Auto、生成式AI等核心板块组成,为开发者提供便捷及高效的学习和交流平台。 高通开发者专区主页:https://qualcomm.csdn.net/
人工智能物联网机器学习 技术论坛(原bbs) 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧