PDA

View Full Version : who can give me an example of using dialog


beans
08-28-2003, 06:58 AM
i am a beginner , who can give me a good example of using
dialog as resoure
thank you.

Bekenn
08-28-2003, 03:39 PM
Well, I'm not sure how others here do it, but here's my method, and it works. This example uses two dialogs; one with a menu control, and one with a static text control and a soft key control.

I'll assume you're using the resource editor that comes with the SDK version 2.0 or above; it's backwards-compatible with BREW 1.x, and has more features.

First, create the string resources that the controls will use. The process is fairly straightforward using the resource editor; just highlight "String" in the left pane, and double-click in the right pane to add each string. I use Unicode for all my string resources, but that doesn't much matter for this exercise. Here's a list of the strings, as well as the identifiers I use:


ID Name Value
1 IDS_MAINMENU Main Menu
2 IDS_MAINHELLO Display Message
3 IDS_MAINEXIT Exit
4 IDS_HELLOTEXT Hello, World!
5 IDS_HELLOBACK Back


Next, create the dialogs in the resource editor. For the first, we'll just include a single control, a menu, that allows us to either display a Hello World message (using the second dialog) or quit the application.

Highlight "Dialog" in the left pane, then double-click in the right pane to add a new dialog. Give it the resource name IDD_MAIN, and add a menu control using the leftmost button under "Dialog Controls." Give the menu the resource name IDC_MAINMENU, the control title IDS_MAINMENU, and two control items, to be named IDCI_MAINHELLO and IDCI_MAINEXIT; once again, just double-click in the Control Items field to add each item. Associate the proper string resource with each control item, and then click OK until you're back at the main window of the resource editor.

Repeat the process for the second dialog, giving it the resource name IDD_HELLO, a soft key menu IDC_HELLOMENU with a control item IDCI_HELLOBACK, and a static control IDC_HELLOTEXT, associating the proper text resources with each.

You're now done with the resource editor; save and compile the resources, putting the output files in your project directory.

I'll assume you already know how to set up a BREW project in Visual Studio and skip the boring details of all that. Ditch whatever default templates the appwizard gives you and use this source instead:

Hello.h

#ifndef HELLO_H
#define HELLO_H

#include "Hello_res.h" // Resource ID definitions
#include "HandlerStack.h"

#include "AEEAppGen.h" // Applet interface definitions

typedef struct _Hello
{
AEEApplet a; // Mandatory first AEEApplet data member
HandlerStack* handler;
} Hello;

#endif


Hello.c

#include "Hello.h" // Applet class definition
#include "Hello.bid" // Applet class ID
#include "HelloMain.h"
#include "HelloHello.h"

//Construction/Destruction:
static boolean Hello_InitAppData(Hello* me);
static void Hello_FreeAppData(Hello* me);

//Hello Event Handlers:
static boolean Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static boolean Hello_EvtAppStart(Hello* me, char* args);
static boolean Hello_EvtAppStop(Hello* me, boolean* closeNow);
static boolean Hello_EvtDialogInit(Hello* me, uint16 id);

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

if(ClsId == AEECLSID_HELLO)
{
if(AEEApplet_New(sizeof(Hello), ClsId, pIShell, po, (IApplet**)ppObj, (AEEHANDLER)Hello_HandleEvent, (PFNFREEAPPDATA)Hello_FreeAppData) == TRUE)
{
if(Hello_InitAppData(*ppObj))
return AEE_SUCCESS;
}
}

return EFAILED;
}

static boolean Hello_InitAppData(Hello* me)
{
me->handler = NULL;
return TRUE;
}

static void Hello_FreeAppData(Hello* me)
{
HandlerStack_Destroy(me->handler);
}

static boolean Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
if(me->handler != NULL && (*me->handler->fn)(me, eCode, wParam, dwParam))
return TRUE;

switch(eCode)
{
case EVT_APP_START:
return Hello_EvtAppStart(me, (char*)dwParam);

case EVT_APP_STOP:
return Hello_EvtAppStop(me, (boolean*)dwParam);

case EVT_DIALOG_INIT:
return Hello_EvtDialogInit(me, wParam);
}

return FALSE;
}

static boolean Hello_EvtAppStart(Hello* me, char* args)
{
ISHELL_CreateDialog(me->a.m_pIShell, HELLO_RES_FILE, IDD_MAIN, NULL);
return TRUE;
}

static boolean Hello_EvtAppStop(Hello* me, boolean* closeNow)
{
return TRUE;
}

static boolean Hello_EvtDialogInit(Hello* me, uint16 id)
{
switch(id)
{
case IDD_MAIN:
me->handler = HandlerStack_Push(me->handler, Hello_Main_HandleEvent);
return TRUE;

case IDD_HELLO:
me->handler = HandlerStack_Push(me->handler, Hello_Hello_HandleEvent);
return TRUE;
}

return FALSE;
}


HelloMain.h

#ifndef HELLOMAIN_H
#define HELLOMAIN_H

#include "Hello.h"

boolean Hello_Main_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam);

#endif


HelloMain.c

#include "HelloMain.h"

static boolean Hello_Main_EvtDialogStart(Hello* me, IDialog* dialog);
static boolean Hello_Main_EvtDialogEnd(Hello* me, IDialog* dialog);

boolean Hello_Main_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:
return Hello_Main_EvtDialogStart(me, (IDialog*)dwParam);

case EVT_DIALOG_END:
return Hello_Main_EvtDialogEnd(me, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_MAINHELLO:
ISHELL_CreateDialog(me->a.m_pIShell, HELLO_RES_FILE, IDD_HELLO, NULL);
return TRUE;

case IDCI_MAINEXIT:
ISHELL_CloseApplet(me->a.m_pIShell, FALSE);
return TRUE;
}

return FALSE;
}

return FALSE;
}

static boolean Hello_Main_EvtDialogStart(Hello* me, IDialog* dialog)
{
return TRUE;
}

static boolean Hello_Main_EvtDialogEnd(Hello* me, IDialog* dialog)
{
me->handler = HandlerStack_Pop(me->handler);
return TRUE;
}


HelloHello.h

#ifndef HELLOHELLO_H
#define HELLOHELLO_H

#include "Hello.h"

boolean Hello_Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam);

#endif


HelloHello.c

#include "HelloHello.h"

#include "AEEStdLib.h"

static boolean Hello_Hello_EvtDialogStart(Hello* me, IDialog* dialog);
static boolean Hello_Hello_EvtDialogEnd(Hello* me, IDialog* dialog);
static boolean Hello_Hello_CmdBack(Hello* me);

boolean Hello_Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:
return Hello_Hello_EvtDialogStart(me, (IDialog*)dwParam);

case EVT_DIALOG_END:
return Hello_Hello_EvtDialogEnd(me, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_HELLOBACK:
return Hello_Hello_CmdBack(me);
}

return FALSE;

case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
ISHELL_EndDialog(me->a.m_pIShell);
return TRUE;
}

return FALSE;
}

return FALSE;
}

static boolean Hello_Hello_EvtDialogStart(Hello* me, IDialog* dialog)
{
AECHAR* buf;
int32 size;
IStatic* text;

text = (IStatic*)IDIALOG_GetControl(dialog, IDC_HELLOTEXT);
ISHELL_GetResSize(me->a.m_pIShell, HELLO_RES_FILE, IDS_HELLOTEXT, RESTYPE_STRING, &size);
buf = (AECHAR*)MALLOC(size);
ISHELL_LoadResString(me->a.m_pIShell, HELLO_RES_FILE, IDS_HELLOTEXT, buf, size);
ISTATIC_SetTextEx(text, buf, NULL, FALSE);
FREE(buf);
return TRUE;
}

static boolean Hello_Hello_EvtDialogEnd(Hello* me, IDialog* dialog)
{
me->handler = HandlerStack_Pop(me->handler);
return TRUE;
}

static boolean Hello_Hello_CmdBack(Hello* me)
{
ISHELL_EndDialog(me->a.m_pIShell);
return TRUE;
}


HandlerStack.h

#ifndef HANDLERSTACK_H
#define HANDLERSTACK_H

#include "AEEAppGen.h"

typedef struct _HandlerStack HandlerStack;

struct _HandlerStack
{
AEEHANDLER fn; // Event handler function
HandlerStack* next; // Pointer to the rest of the stack
};

HandlerStack* HandlerStack_Push(HandlerStack* stack, AEEHANDLER fn);
HandlerStack* HandlerStack_Pop(HandlerStack* stack);
void HandlerStack_Destroy(HandlerStack* stack);

#endif


HandlerStack.c

#include "HandlerStack.h"
#include "AEEStdLib.h"

HandlerStack* HandlerStack_Push(HandlerStack* stack, AEEHANDLER fn)
{
HandlerStack* top = MALLOCREC(HandlerStack);

top->fn = fn;
top->next = stack;
return top;
}

HandlerStack* HandlerStack_Pop(HandlerStack* stack)
{
HandlerStack* top = stack->next;

FREE(stack);
return top;
}

void HandlerStack_Destroy(HandlerStack* stack)
{
HandlerStack* top = stack;
HandlerStack* next = top;

while(top != NULL)
{
next = top->next;
FREE(top);
top = next;
}
}


If you have further questions -- want me to elaborate on something in the code, or, hell, explain why it works -- just ask.

Bekenn
08-28-2003, 07:56 PM
Hmm... I just realized that this is the 2.1 board, as opposed to the 1.1 board. This makes the whole HandlerStack thing completely unnecessary; instead make the following changes:

In Hello.h:

Remove the HandlerStack #include line.
Remove the handler member variable from the Hello struct.

The other files that change are reproduced below, as that's easier than explaining exactly what changed. Note that HandlerStack.h and HandlerStack.c have been removed.

Hello.c:

#include "Hello.h" // Applet class definition
#include "Hello.bid" // Applet class ID
#include "HelloMain.h"
#include "HelloHello.h"

//Construction/Destruction:
static boolean Hello_InitAppData(Hello* me);
static void Hello_FreeAppData(Hello* me);

//Hello Event Handlers:
static boolean Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static boolean Hello_EvtAppStart(Hello* me, char* args);
static boolean Hello_EvtAppStop(Hello* me, boolean* closeNow);
static boolean Hello_EvtDialogInit(Hello* me, uint16 id, IDialog* dialog);

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

if(ClsId == AEECLSID_HELLO)
{
if(AEEApplet_New(sizeof(Hello), ClsId, pIShell, po, (IApplet**)ppObj, (AEEHANDLER)Hello_HandleEvent, (PFNFREEAPPDATA)Hello_FreeAppData) == TRUE)
{
if(Hello_InitAppData(*ppObj))
return AEE_SUCCESS;
}
}

return EFAILED;
}

static boolean Hello_InitAppData(Hello* me)
{
return TRUE;
}

static void Hello_FreeAppData(Hello* me)
{
}

static boolean Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_APP_START:
return Hello_EvtAppStart(me, (char*)dwParam);

case EVT_APP_STOP:
return Hello_EvtAppStop(me, (boolean*)dwParam);

case EVT_DIALOG_INIT:
return Hello_EvtDialogInit(me, wParam, (IDialog*)dwParam);
}

return FALSE;
}

static boolean Hello_EvtAppStart(Hello* me, char* args)
{
ISHELL_CreateDialog(me->a.m_pIShell, HELLO_RES_FILE, IDD_MAIN, NULL);
return TRUE;
}

static boolean Hello_EvtAppStop(Hello* me, boolean* closeNow)
{
return TRUE;
}

static boolean Hello_EvtDialogInit(Hello* me, uint16 id, IDialog* dialog)
{
switch(id)
{
case IDD_MAIN:
IDIALOG_SetProperties(dialog, DLG_HANDLE_ALL_EVENTS);
IDIALOG_SetEventHandler(dialog, Hello_Main_HandleEvent, me);
return TRUE;

case IDD_HELLO:
IDIALOG_SetProperties(dialog, DLG_HANDLE_ALL_EVENTS);
IDIALOG_SetEventHandler(dialog, Hello_Hello_HandleEvent, me);
return TRUE;
}

return FALSE;
}


HelloMain.c:

#include "HelloMain.h"

static boolean Hello_Main_EvtDialogStart(Hello* me, IDialog* dialog);
static boolean Hello_Main_EvtDialogEnd(Hello* me, IDialog* dialog);

boolean Hello_Main_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:
return Hello_Main_EvtDialogStart(me, (IDialog*)dwParam);

case EVT_DIALOG_END:
return Hello_Main_EvtDialogEnd(me, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_MAINHELLO:
ISHELL_CreateDialog(me->a.m_pIShell, HELLO_RES_FILE, IDD_HELLO, NULL);
return TRUE;

case IDCI_MAINEXIT:
ISHELL_CloseApplet(me->a.m_pIShell, FALSE);
return TRUE;
}

return FALSE;
}

return FALSE;
}

static boolean Hello_Main_EvtDialogStart(Hello* me, IDialog* dialog)
{
return TRUE;
}

static boolean Hello_Main_EvtDialogEnd(Hello* me, IDialog* dialog)
{
return TRUE;
}


HelloHello.c

#include "HelloHello.h"

#include "AEEStdLib.h"

static boolean Hello_Hello_EvtDialogStart(Hello* me, IDialog* dialog);
static boolean Hello_Hello_EvtDialogEnd(Hello* me, IDialog* dialog);
static boolean Hello_Hello_CmdBack(Hello* me);

boolean Hello_Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:
return Hello_Hello_EvtDialogStart(me, (IDialog*)dwParam);

case EVT_DIALOG_END:
return Hello_Hello_EvtDialogEnd(me, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_HELLOBACK:
return Hello_Hello_CmdBack(me);
}

return FALSE;

case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
ISHELL_EndDialog(me->a.m_pIShell);
return TRUE;
}

return FALSE;
}

return FALSE;
}

static boolean Hello_Hello_EvtDialogStart(Hello* me, IDialog* dialog)
{
return TRUE;
}

static boolean Hello_Hello_EvtDialogEnd(Hello* me, IDialog* dialog)
{
return TRUE;
}

static boolean Hello_Hello_CmdBack(Hello* me)
{
ISHELL_EndDialog(me->a.m_pIShell);
return TRUE;
}


I considered editing the original post with this update, but I thought it might be more interesting to keep that one intact to show the differences between doing this in 1.1 and doing this in 2.1.

beans
08-28-2003, 07:59 PM
thank you Bekenn,with your sincerely help , i've done it ^^
you are either a good programmer or a good teacher.
i will study more at the code that you give me.
if you can offer more about ISound Interface,ISoundPlayer Interface and IMedia Interface . i will happy more.

thank you again. Bekenn, you save me. :)

Bekenn
08-28-2003, 08:00 PM
Well, thus far, I've not done anything with any of those interfaces; I'm still working on my first commercial app, actually, and that's in 1.1.

Glad to be of some help.

beans
08-29-2003, 02:15 AM
Well Bekenn,i've done a perfect Menu with your help. :)

i want to make it more beautiful, i want to change it's background color and some other styles.can you offer some code?
it seems need a pointer of its own struct.... but i can't
finish ....
thank you.

Bekenn
08-29-2003, 02:27 AM
The function you're looking for is IMENUCTL_SetColors. You can use it in your dialog's EvtDialogStart function, like this:


static boolean Hello_Main_EvtDialogStart(Hello* me, IDialog* dialog)
{
AEEMenuColors colors;
IMenuCtl* menu = (IMenuCtl*)IDIALOG_GetControl(dialog, IDC_MAINMENU);

colors.cBack = MAKE_RGB(0x00, 0xFF, 0x00);
colors.wMask = MC_BACK;
IMENUCTL_SetColors(menu, &colors);
return TRUE;
}


You'll also have to remember to #include AEEMenu.h.

That should make the menu background a nice ugly shade of green, though as the documentation mentions, it's not totally consistent; it doesn't work for 3-D framed obects. I haven't actually tested this code, unlike the previous example, but it should do the trick.

Note also that you do not need to release pointers acquired using IDIALOG_GetControl.

beans
08-31-2003, 06:49 PM
thank you Bekenn,i have done a small game in brew and i begin to love it. thank you.

frankfang
12-06-2003, 02:46 AM
I made a menu with your help, but it can't run.
I use dbgevent() to output events applet recevied,
and I saw there is no "evt_dialog_init" after "evt_app_start".
Give me some help, thank you!

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

FILE: GetMenu.c
===========================================================================*/


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

#include "AEEStdLib.h"

#include "GetMenu.bid"
#include "GetMenu.brh"


/*struct to contain AEEHANDLER*/
typedef struct _HandlerStack HandlerStack;
struct _HandlerStack
{
AEEHANDLER fn; // Event handler function 用于描述消息处理函
//訽型的参数
HandlerStack* next; // Pointer to the rest of the stack
};


/*APPLET struct*/
typedef struct _GetMenuApp
{
AEEApplet a;
HandlerStack* handler;
}
GetMenuApp;


/*constructor and destructor*/
static boolean GetMenu_InitAppData(GetMenuApp* pMe);
static void GetMenu_FreeAppData(GetMenuApp* pMe);


/*applet event handlers*/
static boolean GetMenu_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean GetMenu_EvtAppStart(GetMenuApp* pMe, char* args);
static boolean GetMenu_EvtAppStop(GetMenuApp* pMe, boolean* closeNow);
static boolean GetMenu_EvtDialogInit(GetMenuApp* pMe, uint16 id);


/*mainscreen event handlers*/
static boolean GetMenu_Mainscreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean GetMenu_Mainscreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog);
static boolean GetMenu_Mainscreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog);


/*queryscreen event handlers*/
boolean GetMenu_Queryscreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean GetMenu_Queryscreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog);
static boolean GetMenu_Queryscreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog);


/*balancescreen event handlers*/
boolean GetMenu_Balancescreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean GetMenu_Balancescreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog);
static boolean GetMenu_Balancescreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog);
static boolean GetMenu_Balancescreen_CmdBack(GetMenuApp* pMe);


/*AEEHANDLER stack opreator*/
HandlerStack* HandlerStack_Push(HandlerStack* stack, AEEHANDLER fn);
HandlerStack* HandlerStack_Pop(HandlerStack* stack);
void HandlerStack_Destroy(HandlerStack* stack);


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

if(ClsId == AEECLSID_GETMENU)
{
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell, po, (IApplet**)ppObj,
(AEEHANDLER)GetMenu_HandleEvent,
(PFNFREEAPPDATA)GetMenu_FreeAppData) == TRUE)
{
if(GetMenu_InitAppData(*ppObj))
{
DBGPRINTF("INITAPPDATA \n");//DBG

return AEE_SUCCESS;
}

}
}
return (EFAILED);
}

static boolean GetMenu_InitAppData(GetMenuApp* pMe)
{
pMe->handler = NULL;
return TRUE;
}

static void GetMenu_FreeAppData(GetMenuApp* pMe)
{
HandlerStack_Destroy(pMe->handler);
}

static boolean GetMenu_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)
{
if(pMe->handler != NULL && (*pMe->handler->fn)(pMe, eCode, wParam, dwParam))
return TRUE;

//DBGPRINTF("%e, %e \n", eCode, wParam);//DBG
//DBGPRINTF("%d \n", dwParam);//DBG
DBGEVENT(eCode, NULL);//DBG

switch(eCode)
{
case EVT_APP_START:
return GetMenu_EvtAppStart(pMe, (char*)dwParam);

case EVT_APP_STOP:
return GetMenu_EvtAppStop(pMe, (boolean*)dwParam);

case EVT_DIALOG_INIT:
return GetMenu_EvtDialogInit(pMe, wParam);
}
return FALSE;
}

static boolean GetMenu_EvtAppStart(GetMenuApp* pMe, char* args)
{
//uint16 i;
ISHELL_CreateDialog(pMe->a.m_pIShell, GETMENU_RES_FILE, IDD_MAINSCREEN, NULL);
//i = ISHELL_CreateDialog(pMe->a.m_pIShell, GETMENU_RES_FILE, IDD_MAIN, NULL);

DBGPRINTF("EVTAPPSTART \n");//DBG
//DBGPRINTF("%S \n", i);//DBG

return TRUE;
}

static boolean GetMenu_EvtAppStop(GetMenuApp* pMe, boolean* closeNow)
{
DBGPRINTF("EVTAPPSTART \n");//DBG

return TRUE;
}

static boolean GetMenu_EvtDialogInit(GetMenuApp* pMe, uint16 id)
{
DBGPRINTF("EVTDIALOGINIT \n");//DBG
DBGPRINTF("%d", id);//DBG

switch(id)
{
case IDD_MAINSCREEN:
pMe->handler = HandlerStack_Push(pMe->handler, GetMenu_Mainscreen_HandleEvent);
return TRUE;

case IDD_QUERYSCREEN:
pMe->handler = HandlerStack_Push(pMe->handler, GetMenu_Queryscreen_HandleEvent);
return TRUE;

case IDD_BALANCESCREEN:
pMe->handler = HandlerStack_Push(pMe->handler, GetMenu_Balancescreen_HandleEvent);
return TRUE;
}

return FALSE;
}


boolean GetMenu_Mainscreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:

//DBGPRINTF("EVT_DIALOG_START");

return GetMenu_Mainscreen_EvtDialogStart(pMe, (IDialog*)dwParam);

case EVT_DIALOG_END:

//DBGPRINTF("EVT_DIALOG_END");

return GetMenu_Mainscreen_EvtDialogEnd(pMe, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_MAINSCREEN_QUERY:

//DBGPRINTF("EVT_COMMAND");

ISHELL_CreateDialog(pMe->a.m_pIShell, GETMENU_RES_FILE, IDD_QUERYSCREEN, NULL);
return TRUE;

case IDCI_MAINSCREEN_CONFIG:

//DBGPRINTF("IDCI_MAINEXIT");
return TRUE;

case IDCI_MAINSCREEN_LOSSREPORT:
case IDCI_MAINSCREEN_HELP:
return TRUE;

}

return FALSE;
}

return FALSE;
}

static boolean GetMenu_Mainscreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog)
{
return TRUE;
}

static boolean GetMenu_Mainscreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog)
{
pMe->handler = HandlerStack_Pop(pMe->handler);
return TRUE;
}


boolean GetMenu_Queryscreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:

//DBGPRINTF("EVT_DIALOG_START");

return GetMenu_Queryscreen_EvtDialogStart(pMe, (IDialog*)dwParam);

case EVT_DIALOG_END:

//DBGPRINTF("EVT_DIALOG_END");

return GetMenu_Queryscreen_EvtDialogEnd(pMe, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_QUERYSCREEN_BALANCE:
ISHELL_CreateDialog(pMe->a.m_pIShell, GETMENU_RES_FILE, IDD_BALANCESCREEN, NULL);
return TRUE;

case IDCI_QUERYSCREEN_DETAIL:
case IDCI_QUERYSCREEN_RATE:
case IDCI_QUERYSCREEN_SIGNUP:
return TRUE;

}

return FALSE;

case EVT_KEY:
switch(wParam)
{
case AVK_CLR:

//DBGPRINTF("AVK_CLR");

ISHELL_EndDialog(pMe->a.m_pIShell);
return TRUE;
}

return FALSE;
}

return FALSE;
}

static boolean GetMenu_Queryscreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog)
{
/*
AECHAR* buf;
int32 size;
IStatic* text;

text = (IStatic*)IDIALOG_GetControl(dialog, IDC_HELLOTEXT);
ISHELL_GetResSize(me->a.m_pIShell, HELLO_RES_FILE, IDS_HELLOTEXT, RESTYPE_STRING, &size);
buf = (AECHAR*)MALLOC(size);
ISHELL_LoadResString(me->a.m_pIShell, HELLO_RES_FILE, IDS_HELLOTEXT, buf, size);
//ISTATIC_SetTextEx(text, buf, NULL, FALSE);
FREE(buf);
return TRUE;
*/

return TRUE;
}

static boolean GetMenu_Queryscreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog)
{
pMe->handler = HandlerStack_Pop(pMe->handler);
return TRUE;
}



boolean GetMenu_Balancescreen_HandleEvent(GetMenuApp* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)
{
switch(eCode)
{
case EVT_DIALOG_START:
return GetMenu_Balancescreen_EvtDialogStart(pMe, (IDialog*)dwParam);

case EVT_DIALOG_END:
return GetMenu_Balancescreen_EvtDialogEnd(pMe, (IDialog*)dwParam);

case EVT_COMMAND:
switch(wParam)
{
case IDCI_BALANCESCREEN_BACK:
return GetMenu_Balancescreen_CmdBack(pMe);
}
return FALSE;

case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
ISHELL_EndDialog(pMe->a.m_pIShell);
return TRUE;
}
return FALSE;
}
return FALSE;
}

static boolean GetMenu_Balancescreen_EvtDialogStart(GetMenuApp* pMe, IDialog* dialog)
{
AECHAR* buf;
int32 size;
IStatic* text;

text = (IStatic*)IDIALOG_GetControl(dialog, IDC_BALANCESCREEN_TEXT);
ISHELL_GetResSize(pMe->a.m_pIShell, GETMENU_RES_FILE, IDS_BALANCESCREEN_TEXT, RESTYPE_STRING, &size);
buf = (AECHAR*)MALLOC(size);
ISHELL_LoadResString(pMe->a.m_pIShell, GETMENU_RES_FILE, IDS_BALANCESCREEN_TEXT, buf, size);
//ISTATIC_SetTextEx(text, buf, NULL, FALSE);
FREE(buf);
return TRUE;
}

static boolean GetMenu_Balancescreen_EvtDialogEnd(GetMenuApp* pMe, IDialog* dialog)
{
pMe->handler = HandlerStack_Pop(pMe->handler);
return TRUE;
}

static boolean GetMenu_Balancescreen_CmdBack(GetMenuApp* pMe)
{
ISHELL_EndDialog(pMe->a.m_pIShell);
return TRUE;
}



HandlerStack* HandlerStack_Push(HandlerStack* stack, AEEHANDLER fn)
{
HandlerStack* top = MALLOCREC(HandlerStack);

top->fn = fn;
top->next = stack;
return top;
}

HandlerStack* HandlerStack_Pop(HandlerStack* stack)
{
HandlerStack* top = stack->next;

FREE(stack);
return top;
}

void HandlerStack_Destroy(HandlerStack* stack)
{
HandlerStack* top = stack;
HandlerStack* next = top;

while(top != NULL)
{
next = top->next;
FREE(top);
top = next;
}
}

Bekenn
12-06-2003, 05:56 PM
If you're not getting EVT_DIALOG_INIT, then that probably means that the call to ISHELL_CreateDialog fails. Check the return value for that function.

Also, I noticed that GetMenu_EvtAppStop contains the line:
DBGPRINTF("EVTAPPSTART \n");//DBG

Might want to change that for debug purposes.

frankfang
12-06-2003, 10:38 PM
Thanks for your reply!
Yes, I output the value create_dialog() returned, and found
the functio did't work.

I can't find out the reason.

Will wrong applet configration result in it?

I use vs.net and config it with the help of docs qualcomm offered,
My bew vertion is 3.0.

Bekenn
12-08-2003, 12:40 AM
I'm afraid I don't know what the problem is; all I can really suggest is that you make sure your resource file is up-to-date (in versions 2.1 and below, this is typically named <PROJECTNAME>_res.h; it looks like yours is named GetMenu.brh).

Also note that, as I mentioned in my second post above, you don't need to use HandlerStack in BREW 2.0 and above.

What exactly is the error code you're getting from ISHELL_CreateDialog?

frankfang
12-08-2003, 01:59 AM
The error code from "ishell_create()" is "EFAILED".
I use sdk 3.0 , and the resource header file name is "XXX.brh".

Thank you for your help!

Bekenn
12-08-2003, 05:34 PM
Have you opened up the .brh file to make sure that the definitions are right?

frankfang
12-08-2003, 10:56 PM
Yes , I have seen and make sure of that.

I find that after I have finished a applet and run it properly, I can't change the resource file name using resource editor(I also modify the correspongding code in program ).I don't konw I made mistakes somewhere else or brew resource editor is designed to stop developers doing this.

I want to ask another problem:
After I have arrange the sequence of the contorls in reource editor ,can I change the sequence again? or I can only delete all the controls and restart to organize them?

I did't find the instruction from user guide.

Thank you!

Bekenn
12-09-2003, 02:22 AM
You should be able to just change the resource IDs of each of the controls to rearrange their order.

frankfang
12-09-2003, 08:26 AM
Thank you for your help!

Murray Bonner
12-09-2003, 09:52 AM
This article (http://www.devx.com/Brew/Article/11619) deals with handling dialogs at runtime.

seberline
12-18-2003, 07:16 PM
Bekenn,

Could you please elaborate a bit on your event handler stack,
what it accomplishes in BREW 1.1, and why it's no longer needed
in BREW 2.0+?

Regards,

Bekenn
12-22-2003, 08:52 AM
Sure.

It's exactly what you described by the words "event handler stack"; it's a stack of pointers to functions that work as event handlers. When the BREW framework passes an event on to the applet, the applet first sends that event to the top item on the stack:


static boolean Hello_HandleEvent(Hello* me, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
// check top item on handler stack
if(me->handler != NULL && (*me->handler->fn)(me, eCode, wParam, dwParam))
return TRUE; // top handler took care of it

// default handling
}


If that event handler can't handle the event, then the default event handler takes a crack at it. The stack of event handlers matches the stack of dialogs in the applet; in this way, each dialog has its own event handler, in which you can uniquely specify how you want each dialog to react to any given event. Most often, the events we care about are EVT_COMMAND, EVT_DIALOG_START, EVT_DIALOG_END, and the EVT_KEY events.

This behavior matches the behavior induced by these two lines:


IDIALOG_SetProperties(dialog, DLG_HANDLE_ALL_EVENTS);
IDIALOG_SetEventHandler(dialog, APP_DLG_HandleEvent, me);


However, I found that those two lines didn't work properly when compiling for BREW 1.1. My default event handler kept getting events intended for my dialogs, so I wrote HandlerStack as a work-around.

I've also written a nearly identical stack that I use to keep track of dialog-specific data.