Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,

 

I have done a sample app in which i have used a title widget to draw the just title. So here if i launch the application it is drawing blank screen. Most of the times say 70% it is happening like this. But if i debug the code, it is drawing the screen. Means i observed that to draw a widget it is taking time. Why it is like this or Is this the behavior? I'm struck here.

 

Thanks

Jithendra

Some sample code would make it easier for the community to offer suggestions.  In the meantime, make sure that you:

Check that the extent is set on the title
Make sure that the widget is visible in the parent container it resides
Check the position within the parent container.

 
Also can you tell me if you are using BTFE or the default font?  Sample code would help clarify this.
 
Thanks,
Jason

Some sample code would make it easier for the community to offer suggestions.  In the meantime, make sure that you:

Check that the extent is set on the title
Make sure that the widget is visible in the parent container it resides
Check the position within the parent container.

 
Also can you tell me if you are using BTFE or the default font?  Sample code would help clarify this.
 
Thanks,
Jason

Here is the working code snippet for your reference:
WidgetExtent we;
int nErr = 0;
IWidget *piwTitle = 0;

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_TitleWidget, (void**)&me->piwTtl) );
ERR_TRY( IWidget_GetProperty(me->piwTtl, PROP_TITLEWIDGET, &piwTitle ));

// setup title (static) widget
(void) IWidget_SetPadding(piwTitle, 2);
(void) IWidget_SetFlags(piwTitle, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
(void) IWidget_SetBGColor(piwTitle, RGB_WHITE);
(void) IWidget_SetFGColor(piwTitle, RGB_BLACK);

ERR_TRY( IWIDGET_SetText(piwTitle, L"test", 0) );
IWidget_SetPreferredExtent(piwTitle, NULL);

// setup Title widget
(void) IWidget_SetBorderWidth(me->piwTtl, 4);
(void) IWidget_SetBorderStyle(me->piwTtl, BORDERSTYLE_ROUNDED);
(void) IWidget_SetPadding(me->piwTtl, 2);
(void) IWidget_SetBorderColor(me->piwTtl, RGB_BLACK);
(void) IWidget_SetBGColor(me->piwTtl, RGB_WHITE);
IWidget_GetPreferredExtent(me->piwTtl, &we);
IWidget_SetExtent(me->piwTtl, &we);

wp.x = 10;
wp.y = 50;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwTtl, WIDGET_ZTOPMOST, &wp) );

ERR_CATCH:
RELEASEIF(piwTitle);

Here is the working code snippet for your reference:
WidgetExtent we;
int nErr = 0;
IWidget *piwTitle = 0;

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_TitleWidget, (void**)&me->piwTtl) );
ERR_TRY( IWidget_GetProperty(me->piwTtl, PROP_TITLEWIDGET, &piwTitle ));

// setup title (static) widget
(void) IWidget_SetPadding(piwTitle, 2);
(void) IWidget_SetFlags(piwTitle, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
(void) IWidget_SetBGColor(piwTitle, RGB_WHITE);
(void) IWidget_SetFGColor(piwTitle, RGB_BLACK);

ERR_TRY( IWIDGET_SetText(piwTitle, L"test", 0) );
IWidget_SetPreferredExtent(piwTitle, NULL);

// setup Title widget
(void) IWidget_SetBorderWidth(me->piwTtl, 4);
(void) IWidget_SetBorderStyle(me->piwTtl, BORDERSTYLE_ROUNDED);
(void) IWidget_SetPadding(me->piwTtl, 2);
(void) IWidget_SetBorderColor(me->piwTtl, RGB_BLACK);
(void) IWidget_SetBGColor(me->piwTtl, RGB_WHITE);
IWidget_GetPreferredExtent(me->piwTtl, &we);
IWidget_SetExtent(me->piwTtl, &we);

wp.x = 10;
wp.y = 50;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwTtl, WIDGET_ZTOPMOST, &wp) );

ERR_CATCH:
RELEASEIF(piwTitle);

Hi ,
 
Thanks for ur reply. I'm clear with using title widget. If i launch the app without debug it is not drawing. But if i debug, it is drawing( I guess it takes some time). I'm attaching my code.
 
___________________________________-
 
/*=============================================================================
FILE: titlewid.c
=============================================================================*/

/*=============================================================================
This QUALCOMM Sample Code Disclaimer applies to the sample code of
QUALCOMM Incorporated (“QUALCOMM”) to which it is attached or in which it is
integrated (“Sample Code”). Qualcomm is a trademark of, and may not be used
without express written permission of, QUALCOMM.

Disclaimer of Warranty. Unless required by applicable law or agreed to in
writing, QUALCOMM provides the Sample Code on an "as is" basis, without
warranties or conditions of any kind, either express or implied, including,
without limitation, any warranties or conditions of title, non-infringement,
merchantability, or fitness for a particular purpose. You are solely
responsible for determining the appropriateness of using the Sample Code and
assume any risks associated therewith. PLEASE BE ADVISED THAT QUALCOMM WILL NOT
SUPPORT THE SAMPLE CODE OR TROUBLESHOOT ANY ISSUES THAT MAY ARISE WITH IT.

Limitation of Liability. In no event shall QUALCOMM be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages (including,
but not limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any theory
of liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of the Sample Code
even if advised of the possibility of such damage.
=============================================================================*/

/*-----------------------------------------------------------------------------
Includes and Variable Definitions
-----------------------------------------------------------------------------*/
#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.

#define AEE_DBG_HEAP 1
#include "AEEStdlib.h"

#include "titlewid.bid"
#include "titlewid_res.h"

#include "AEERootContainer.h"
#include "AEERootContainer.bid"

#include "AEEDisplayCanvas.h"
#include "AEEDisplayCanvas.bid"

#include "AEETitleWidget.h"
#include "AEETitleWidget.bid"

/*-----------------------------------------------------------------------------
Applet Structure - Definition of the Applet Structure that's passed to Brew MP
API functions. All variables in here are referenced via the applet structure
pointer "pMe->", and will be able to be referenced as static.
-----------------------------------------------------------------------------*/
typedef struct _titlewid {
AEEApplet applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
// Add your own variables here...

IRootContainer *m_pIRootContainer;
IWidget *m_pIRootWidget;

IWidget *m_pITitleWidget;

titlewid;

/*-----------------------------------------------------------------------------
Function Prototypes
-----------------------------------------------------------------------------*/
static boolean titlewid_HandleEvent(titlewid* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean titlewid_InitAppData(titlewid* pMe);
void titlewid_FreeAppData(titlewid* pMe);
static void titlewid_DrawScreen(titlewid * pMe);
boolean Create_RootContainer(titlewid *pMe);
boolean Draw_TitleWidget(titlewid *pMe);

/*-----------------------------------------------------------------------------
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 the app-specific initialization section every
time, except for a call to IDisplay_InitAppData(). This is done as follows:
InitAppData() is called to initialize the AppletData instance. It is the app
developer's responsibility to fill-in the app data initialization code of
InitAppData(). The app developer is also responsible to release memory
allocated for data contained in AppletData. This is done in
IDisplay_FreeAppData().

PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
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 this app needs to be loaded and if AEEApplet_New()
invocation was successful.

AEE_EFAILED: If this app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, this app will not load.

SIDE EFFECTS:
None
=============================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;

// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_TITLEWID == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(titlewid),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)titlewid_HandleEvent,
(PFNFREEAPPDATA)titlewid_FreeAppData) ) {

// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == titlewid_InitAppData((titlewid*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

/*=============================================================================
FUNCTION: titlewid_InitAppData

DESCRIPTION:
This function is called when the application is starting up, so the
initialization and resource allocation code is executed here.

PROTOTYPE:
boolean titlewid_InitAppData(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
TRUE if there were no failures.

SIDE EFFECTS:
None
=============================================================================*/
boolean titlewid_InitAppData(titlewid * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->applet.m_pIDisplay;
pMe->piShell = pMe->applet.m_pIShell;

// 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->applet.m_pIShell,&pMe->deviceInfo);

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

return TRUE;// No failures up to this point, so return success.

/*=============================================================================
FUNCTION: titlewid_FreeAppData

DESCRIPTION:
This function is called when the application is exiting, so free the
allocated resources, etc.

PROTOTYPE:
void titlewid_HandleEvent(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
None

SIDE EFFECTS:
None
=============================================================================*/
void titlewid_FreeAppData(titlewid * pMe)
{
// Insert your code here for freeing any resources you have allocated...

// Example to use for releasing each interface:
// if ( NULL != pMe->piMenuCtl ) { // check for NULL first
// IMenuCtl_Release(pMe->piMenuCtl)// release the interface
// pMe->piMenuCtl = NULL; // set to NULL so no problems later
// }
//

if(pMe->m_pITitleWidget)
{
//IRootContainer_Remove(pMe->m_pIRootContainer, pMe->m_pITitleWidget);
IWIDGET_Release(pMe->m_pITitleWidget);
pMe->m_pITitleWidget = NULL;
}

if(pMe->m_pIRootWidget)
{
//IRootContainer_Remove(pMe->m_pIRootContainer, pMe->m_pIRootWidget);
IWIDGET_Release(pMe->m_pIRootWidget);
pMe->m_pIRootWidget = NULL;
}

if(pMe->m_pIRootContainer)
{

IRootContainer_Release(pMe->m_pIRootContainer);
pMe->m_pIRootContainer = NULL;
}

/*=============================================================================
FUNCTION: titlewid_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:
static boolean titlewid_HandleEvent(IApplet * pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

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 titlewid_HandleEvent(titlewid* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
// Event to inform app to start, so start-up code is here:
case EVT_APP_START:
//titlewid_DrawScreen(pMe); // Draw text on display screen.
Create_RootContainer(pMe);
Draw_TitleWidget(pMe);
return TRUE;

// Event to inform app to exit, so shut-down code is here:
case EVT_APP_STOP:
return TRUE;

// Event to inform app to suspend, so suspend code is here:
case EVT_APP_SUSPEND:
return TRUE;

// Event to inform app to resume, so resume code is here:
case EVT_APP_RESUME:
titlewid_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;

// An SMS message has arrived for this app.
// The 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:
return TRUE;

// A key was pressed:
case EVT_KEY:
return FALSE;

// Clamshell has opened/closed
// wParam = TRUE if open, FALSE if closed
case EVT_FLIP:
return TRUE;

// Clamtype device is closed and reexposed when opened, and LCD
// is blocked, or keys are locked by software.
// wParam = TRUE if keygaurd is on
case EVT_KEYGUARD:
return TRUE;

// If event wasn't handled here, then break out:
default:
break;
}
if(pMe->m_pIRootWidget)
{
boolean bReturn;
bReturn = IWidget_HandleEvent(pMe->m_pIRootWidget, eCode, wParam, dwParam);
return TRUE;
}
return FALSE; // Event wasn't handled.

/*=============================================================================
FUNCTION: titlewid_DrawScreen

DESCRIPTION:
Draw text in the middle of the display screen.

PROTOTYPE:
static void titlewid_DrawScreen(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
None

SIDE EFFECTS:
None
=============================================================================*/
static void titlewid_DrawScreen(titlewid * pMe)
{
AECHAR szBuf[64] = {0};
int nStrLen = 0;
RGBVAL oldTextColor = RGB_BLACK;

IDisplay_ClearScreen(pMe->piDisplay); // Erase whole screen.

// Load the string resource into a buffer:
nStrLen = ISHELL_LoadResString(pMe->piShell,
TITLEWID_RES_FILE,
IDS_STRING_1001, szBuf, sizeof(szBuf));

// If the text was successfully loaded from resource file into buffer:
if (0 < nStrLen) {
// Set user-text color to black:
oldTextColor = IDisplay_SetColor(pMe->piDisplay,
CLR_USER_TEXT,
RGB_BLACK);

IDisplay_DrawText(pMe->piDisplay, // Display instance.
AEE_FONT_BOLD, // Use Bold font.
szBuf, // String buffer containing text.
-1, // Automatically compute string length.
0, // x-coordinate ignored since IDF_ALIGN_CENTER.
0, // y-coordinate ignored since IDF_ALIGN_MIDDLE.
NULL, // No clipping.
IDF_ALIGN_CENTER | // Center-align horizontally.
IDF_ALIGN_MIDDLE); // Middle-align vertically.
}

// Restore previous color:
IDisplay_SetColor(pMe->piDisplay, CLR_USER_TEXT, oldTextColor);

IDisplay_Update (pMe->piDisplay);

boolean Create_RootContainer(titlewid *pMe)
{
IDisplayCanvas *pIDisplayCanvas;
int nErr = 0;
AEERect rec;
if(!pMe)
return FALSE;

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_DisplayCanvas, (void **)&pIDisplayCanvas) != SUCCESS)
return FALSE;

IDisplayCanvas_SetDisplay(pIDisplayCanvas, pMe->piDisplay);

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_RootContainer, (void **)&pMe->m_pIRootContainer) != SUCCESS)
return FALSE;

nErr = IRootContainer_QueryInterface(pMe->m_pIRootContainer, AEEIID_WIDGET, (void **)&pMe->m_pIRootWidget);

SETAEERECT(&rec, 0, 0, &pMe->deviceInfo.cxScreen, &pMe->deviceInfo.cyScreen);
IRootContainer_SetCanvas(pMe->m_pIRootContainer, (ICanvas *)pIDisplayCanvas, &rec);

IWidget_EnableTouch(pMe->m_pIRootWidget);
IDisplayCanvas_Release(pIDisplayCanvas);
return TRUE;

boolean Draw_TitleWidget(titlewid *pMe)
{
int nErr = 0;
IFont *pIFont;
WidgetPos dwPos = {0,0,0};
WidgetExtent we = {0,0};
IWidget* pTitleStatic=NULL;

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_TitleWidget, (void **)&pMe->m_pITitleWidget) != SUCCESS)
return FALSE;

IWIDGET_GetProperty(pMe->m_pITitleWidget, PROP_TITLEWIDGET, (uint32 *)&pTitleStatic);

we.height = 30;
we.width = pMe->deviceInfo.cxScreen;
IWIDGET_SetExtent(pMe->m_pITitleWidget, &we);

IWIDGET_SetText(pTitleStatic, L"Main Menu", TRUE);
IWidget_SetFlags(pTitleStatic, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);

nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_FONTSYSLARGE, (void **)&pIFont);
IWidget_SetFont(pTitleStatic, pIFont);
IWidget_SetBorderColor(pMe->m_pITitleWidget, MAKE_RGB(0,125,0));
IWidget_SetBGColor(pMe->m_pITitleWidget, MAKE_RGB(255,0,0));

//pTitleStatic = NULL;

//pIFont = NULL;

dwPos.x = 0;
dwPos.y = 0;
dwPos.bVisible = TRUE;
(void)IRootContainer_Insert(pMe->m_pIRootContainer, pMe->m_pITitleWidget, WIDGET_ZNORMAL,&dwPos);

IFont_Release(pIFont);
IWIDGET_Release(pTitleStatic);
return TRUE;

Hi ,
 
Thanks for ur reply. I'm clear with using title widget. If i launch the app without debug it is not drawing. But if i debug, it is drawing( I guess it takes some time). I'm attaching my code.
 
___________________________________-
 
/*=============================================================================
FILE: titlewid.c
=============================================================================*/

/*=============================================================================
This QUALCOMM Sample Code Disclaimer applies to the sample code of
QUALCOMM Incorporated (“QUALCOMM”) to which it is attached or in which it is
integrated (“Sample Code”). Qualcomm is a trademark of, and may not be used
without express written permission of, QUALCOMM.

Disclaimer of Warranty. Unless required by applicable law or agreed to in
writing, QUALCOMM provides the Sample Code on an "as is" basis, without
warranties or conditions of any kind, either express or implied, including,
without limitation, any warranties or conditions of title, non-infringement,
merchantability, or fitness for a particular purpose. You are solely
responsible for determining the appropriateness of using the Sample Code and
assume any risks associated therewith. PLEASE BE ADVISED THAT QUALCOMM WILL NOT
SUPPORT THE SAMPLE CODE OR TROUBLESHOOT ANY ISSUES THAT MAY ARISE WITH IT.

Limitation of Liability. In no event shall QUALCOMM be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages (including,
but not limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any theory
of liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of the Sample Code
even if advised of the possibility of such damage.
=============================================================================*/

/*-----------------------------------------------------------------------------
Includes and Variable Definitions
-----------------------------------------------------------------------------*/
#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.

#define AEE_DBG_HEAP 1
#include "AEEStdlib.h"

#include "titlewid.bid"
#include "titlewid_res.h"

#include "AEERootContainer.h"
#include "AEERootContainer.bid"

#include "AEEDisplayCanvas.h"
#include "AEEDisplayCanvas.bid"

#include "AEETitleWidget.h"
#include "AEETitleWidget.bid"

/*-----------------------------------------------------------------------------
Applet Structure - Definition of the Applet Structure that's passed to Brew MP
API functions. All variables in here are referenced via the applet structure
pointer "pMe->", and will be able to be referenced as static.
-----------------------------------------------------------------------------*/
typedef struct _titlewid {
AEEApplet applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
// Add your own variables here...

IRootContainer *m_pIRootContainer;
IWidget *m_pIRootWidget;

IWidget *m_pITitleWidget;

titlewid;

/*-----------------------------------------------------------------------------
Function Prototypes
-----------------------------------------------------------------------------*/
static boolean titlewid_HandleEvent(titlewid* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean titlewid_InitAppData(titlewid* pMe);
void titlewid_FreeAppData(titlewid* pMe);
static void titlewid_DrawScreen(titlewid * pMe);
boolean Create_RootContainer(titlewid *pMe);
boolean Draw_TitleWidget(titlewid *pMe);

/*-----------------------------------------------------------------------------
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 the app-specific initialization section every
time, except for a call to IDisplay_InitAppData(). This is done as follows:
InitAppData() is called to initialize the AppletData instance. It is the app
developer's responsibility to fill-in the app data initialization code of
InitAppData(). The app developer is also responsible to release memory
allocated for data contained in AppletData. This is done in
IDisplay_FreeAppData().

PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
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 this app needs to be loaded and if AEEApplet_New()
invocation was successful.

AEE_EFAILED: If this app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, this app will not load.

SIDE EFFECTS:
None
=============================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;

// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_TITLEWID == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(titlewid),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)titlewid_HandleEvent,
(PFNFREEAPPDATA)titlewid_FreeAppData) ) {

// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == titlewid_InitAppData((titlewid*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

/*=============================================================================
FUNCTION: titlewid_InitAppData

DESCRIPTION:
This function is called when the application is starting up, so the
initialization and resource allocation code is executed here.

PROTOTYPE:
boolean titlewid_InitAppData(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
TRUE if there were no failures.

SIDE EFFECTS:
None
=============================================================================*/
boolean titlewid_InitAppData(titlewid * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->applet.m_pIDisplay;
pMe->piShell = pMe->applet.m_pIShell;

// 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->applet.m_pIShell,&pMe->deviceInfo);

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

return TRUE;// No failures up to this point, so return success.

/*=============================================================================
FUNCTION: titlewid_FreeAppData

DESCRIPTION:
This function is called when the application is exiting, so free the
allocated resources, etc.

PROTOTYPE:
void titlewid_HandleEvent(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
None

SIDE EFFECTS:
None
=============================================================================*/
void titlewid_FreeAppData(titlewid * pMe)
{
// Insert your code here for freeing any resources you have allocated...

// Example to use for releasing each interface:
// if ( NULL != pMe->piMenuCtl ) { // check for NULL first
// IMenuCtl_Release(pMe->piMenuCtl)// release the interface
// pMe->piMenuCtl = NULL; // set to NULL so no problems later
// }
//

if(pMe->m_pITitleWidget)
{
//IRootContainer_Remove(pMe->m_pIRootContainer, pMe->m_pITitleWidget);
IWIDGET_Release(pMe->m_pITitleWidget);
pMe->m_pITitleWidget = NULL;
}

if(pMe->m_pIRootWidget)
{
//IRootContainer_Remove(pMe->m_pIRootContainer, pMe->m_pIRootWidget);
IWIDGET_Release(pMe->m_pIRootWidget);
pMe->m_pIRootWidget = NULL;
}

if(pMe->m_pIRootContainer)
{

IRootContainer_Release(pMe->m_pIRootContainer);
pMe->m_pIRootContainer = NULL;
}

/*=============================================================================
FUNCTION: titlewid_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:
static boolean titlewid_HandleEvent(IApplet * pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

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 titlewid_HandleEvent(titlewid* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
// Event to inform app to start, so start-up code is here:
case EVT_APP_START:
//titlewid_DrawScreen(pMe); // Draw text on display screen.
Create_RootContainer(pMe);
Draw_TitleWidget(pMe);
return TRUE;

// Event to inform app to exit, so shut-down code is here:
case EVT_APP_STOP:
return TRUE;

// Event to inform app to suspend, so suspend code is here:
case EVT_APP_SUSPEND:
return TRUE;

// Event to inform app to resume, so resume code is here:
case EVT_APP_RESUME:
titlewid_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;

// An SMS message has arrived for this app.
// The 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:
return TRUE;

// A key was pressed:
case EVT_KEY:
return FALSE;

// Clamshell has opened/closed
// wParam = TRUE if open, FALSE if closed
case EVT_FLIP:
return TRUE;

// Clamtype device is closed and reexposed when opened, and LCD
// is blocked, or keys are locked by software.
// wParam = TRUE if keygaurd is on
case EVT_KEYGUARD:
return TRUE;

// If event wasn't handled here, then break out:
default:
break;
}
if(pMe->m_pIRootWidget)
{
boolean bReturn;
bReturn = IWidget_HandleEvent(pMe->m_pIRootWidget, eCode, wParam, dwParam);
return TRUE;
}
return FALSE; // Event wasn't handled.

/*=============================================================================
FUNCTION: titlewid_DrawScreen

DESCRIPTION:
Draw text in the middle of the display screen.

PROTOTYPE:
static void titlewid_DrawScreen(titlewid * pMe)

PARAMETERS:
pMe: Pointer to the AEEApplet structure. This structure contains information
specific to this applet. It was initialized during AEEClsCreateInstance().

DEPENDENCIES:
None

RETURN VALUE:
None

SIDE EFFECTS:
None
=============================================================================*/
static void titlewid_DrawScreen(titlewid * pMe)
{
AECHAR szBuf[64] = {0};
int nStrLen = 0;
RGBVAL oldTextColor = RGB_BLACK;

IDisplay_ClearScreen(pMe->piDisplay); // Erase whole screen.

// Load the string resource into a buffer:
nStrLen = ISHELL_LoadResString(pMe->piShell,
TITLEWID_RES_FILE,
IDS_STRING_1001, szBuf, sizeof(szBuf));

// If the text was successfully loaded from resource file into buffer:
if (0 < nStrLen) {
// Set user-text color to black:
oldTextColor = IDisplay_SetColor(pMe->piDisplay,
CLR_USER_TEXT,
RGB_BLACK);

IDisplay_DrawText(pMe->piDisplay, // Display instance.
AEE_FONT_BOLD, // Use Bold font.
szBuf, // String buffer containing text.
-1, // Automatically compute string length.
0, // x-coordinate ignored since IDF_ALIGN_CENTER.
0, // y-coordinate ignored since IDF_ALIGN_MIDDLE.
NULL, // No clipping.
IDF_ALIGN_CENTER | // Center-align horizontally.
IDF_ALIGN_MIDDLE); // Middle-align vertically.
}

// Restore previous color:
IDisplay_SetColor(pMe->piDisplay, CLR_USER_TEXT, oldTextColor);

IDisplay_Update (pMe->piDisplay);

boolean Create_RootContainer(titlewid *pMe)
{
IDisplayCanvas *pIDisplayCanvas;
int nErr = 0;
AEERect rec;
if(!pMe)
return FALSE;

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_DisplayCanvas, (void **)&pIDisplayCanvas) != SUCCESS)
return FALSE;

IDisplayCanvas_SetDisplay(pIDisplayCanvas, pMe->piDisplay);

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_RootContainer, (void **)&pMe->m_pIRootContainer) != SUCCESS)
return FALSE;

nErr = IRootContainer_QueryInterface(pMe->m_pIRootContainer, AEEIID_WIDGET, (void **)&pMe->m_pIRootWidget);

SETAEERECT(&rec, 0, 0, &pMe->deviceInfo.cxScreen, &pMe->deviceInfo.cyScreen);
IRootContainer_SetCanvas(pMe->m_pIRootContainer, (ICanvas *)pIDisplayCanvas, &rec);

IWidget_EnableTouch(pMe->m_pIRootWidget);
IDisplayCanvas_Release(pIDisplayCanvas);
return TRUE;

boolean Draw_TitleWidget(titlewid *pMe)
{
int nErr = 0;
IFont *pIFont;
WidgetPos dwPos = {0,0,0};
WidgetExtent we = {0,0};
IWidget* pTitleStatic=NULL;

if(ISHELL_CreateInstance(pMe->piShell, AEECLSID_TitleWidget, (void **)&pMe->m_pITitleWidget) != SUCCESS)
return FALSE;

IWIDGET_GetProperty(pMe->m_pITitleWidget, PROP_TITLEWIDGET, (uint32 *)&pTitleStatic);

we.height = 30;
we.width = pMe->deviceInfo.cxScreen;
IWIDGET_SetExtent(pMe->m_pITitleWidget, &we);

IWIDGET_SetText(pTitleStatic, L"Main Menu", TRUE);
IWidget_SetFlags(pTitleStatic, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);

nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_FONTSYSLARGE, (void **)&pIFont);
IWidget_SetFont(pTitleStatic, pIFont);
IWidget_SetBorderColor(pMe->m_pITitleWidget, MAKE_RGB(0,125,0));
IWidget_SetBGColor(pMe->m_pITitleWidget, MAKE_RGB(255,0,0));

//pTitleStatic = NULL;

//pIFont = NULL;

dwPos.x = 0;
dwPos.y = 0;
dwPos.bVisible = TRUE;
(void)IRootContainer_Insert(pMe->m_pIRootContainer, pMe->m_pITitleWidget, WIDGET_ZNORMAL,&dwPos);

IFont_Release(pIFont);
IWIDGET_Release(pTitleStatic);
return TRUE;

Please post only required code snippet and not complete code. Atleast dead code/comments can be avoided.
Same code worked for me withut any issues.

Please post only required code snippet and not complete code. Atleast dead code/comments can be avoided.
Same code worked for me withut any issues.