|
How to Use a Simple Resource Dialog with QUALCOMM BREW™
April 2004 by Lauren E. Darcey
This article will attempt to walk you step-by-step through the not-so-difficult process of creating and using a Dialog from a BRX resource file, on the QUALCOMM BREW™ platform. This article assumes you have a working knowledge of the BREW™ SDK, particularly using resource files, various controls and application event handling.
Creating the Dialog Resource
In order to use a dialog in your application, you must first create it in your resource file. A Dialog is composed of a set of inner controls. You can create combinations of various well known controls such as various menu-types, date and time pickers, static and variable text controls, and image controls within your dialog. In this article, we will create a little dialog with an image and some static text.
Open the BREW™ Resource Editor (Version 3.0 in this example), load your resource file. For the purposes of this example, first create two new resources - one text string, and one image. Now, under the Dialogs submenu, right click and create a new Dialog. Name your dialog IDD_DIALOG_KEWL, and set its coordinates, if necessary. Leave the defaults for a full screen, focusless dialog such as the one we shall be creating today. Next click on the Controls attribute, which will bring you to a new screen which allows you to add the inner controls you wish to the Dialog.
Using the buttons for each control, or the shortcut keys (right-click for the listing), add your controls to the dialog, and name them each appropriately. In this case, add a static text field called IDC_STATIC_DIALOGTEXT and an image called IDC_IMAGE_DIALOGIMAGE. Again you may set the coordinates of the inner controls appropriately, as well as set default values. For IDC_STATIC_DIALOGTEXT, you can set the Control Text Attribute to the text resource string you defined earlier. You can also set the Control Image Attribute to the image resource for IDC_IMAGE_DIALOGIMAGE.
Now save and build your resource files. You're ready to use your control.
Create the Dialog
Creating a Dialog is relatively straightforward. When your application determines that it's time for the dialog, it need only call ISHELL_CreateDialog(pApp->a.m_pIShell, RES_FILE, IDD_DIALOG_KEWL, NULL);.
Handling Dialog Events
You must handle three events with dialogs - EVT_DIALOG_START, EVT_DIALOG_INIT, and EVT_DIALOG_END. Use the EVT_DIALOG_START event to set or update any display characteristics of the Dialog or its inner controls. It should be noted that the dwParam actually points to the newly created Dialog.
case EVT_DIALOG_START:
bRet = DisplayDialog(pApp, dwParam);
break;
case EVT_DIALOG_INIT:
case EVT_DIALOG_END:
return TRUE;
break;
Accessing the Inner Controls
So you've now created a new dialog, and caught the EVT_DIALOG_START event, and you'd like to display your dialog. You'll need to call ISHELL_GetActiveDialog(pApp->a.m_pIShell); in order to obtain a pointer to the newly-created dialog (or cast the dwParam from the EVT_DIALOG). Now you're free to manipuate the dialog, and its inner controls, to your heart's content. You'll want to look at IDIALOG_GetControl, in order to access your inner controls, set or retrieve their data, change and redraw them, just as you would inline controls. For example, here's what we might have in DisplayDialog():
IDialog* pDialog = ISHELL_GetActiveDialog(pApp->a.m_pIShell);
// or IDialog* pDialog = (IDialog*)dwParam;
IStatic* pDialogStaticTextCtl = (IStatic*)IDIALOG_GetControl(pDialog , IDC_STATIC_DIALOGTEXT);
IImage* pImage = (IImage*)IDIALOG_GetControl(pDialog , IDC_IMAGE_DIALOGIMAGE);
// Update Controls, Redraw them, etc.
Disposing of a Dialog
Disposing of a Dialog is even more straightforward than creating one. When your application determines that it's time for the dialog to go away, it need only call ISHELL_EndDialog(pApp->a.m_pIShell); to dismiss it.
Other Notes
It should be noted that this is not the only way to create and use a Dialog. It is possible, but much more programmatically difficult to create and use dialogs without defining them within the resource files. |