A very simple form resource is added to the resource file:
helloworld.rcp |
---|
#include "helloworld_rcp.h" VERSION "2.0" ICON "../resources/icon.bmp" SMALLICON "../resources/icon_s.bmp" // The main form FORM ID MainForm AT (0 0 160 160) NOFRAME USABLE BEGIN TITLE "Hello world" END |
the form has a number, MainForm has been defined as 1000
in the include file: helloworld_rcp.h
helloworld_rcp.h // Defines for the Hello world application
#define MainForm 1000
To use the form, some functionality has to be added to the source file:
helloworld.c |
---|
// Include Palm prototypes, variables etc. #include <System/SysAll.h> // Include prototypes, variables etc. for the userinterface #include <UI/UIAll.h> // Include the defines for the ID's of the form #include "helloworld_rcp.h" // Initialises the application Boolean StartApplication(void) { // Start the main form FrmGotoForm(MainForm); return false; } // StartApplication // terminates the application void StopApplication(void) { FrmCloseAllForms(); } // StopApplication Boolean MainFormHandleEvent(EventPtr event) { FormPtr frm; Boolean handled = false; switch (event->eType) { case frmOpenEvent: frm = FrmGetActiveForm(); FrmDrawForm(frm); handled = true; break; } // event->eType return handled; } // MainFormHandleEvent Boolean ApplicationHandleEvent(EventPtr event) { FormPtr frm; Int formId; Boolean handled = false; if (event->eType == frmLoadEvent) { // get the form ID number formId = event->data.frmLoad.formID; // load the form (get it's pointer) frm = FrmInitForm(formId); // make the form active FrmSetActiveForm(frm); switch (formId) { case MainForm: FrmSetEventHandler(frm, MainFormHandleEvent); break; } handled = true; } // frmLoadEvent return handled; } // ApplicationHandleEvent // Entry point for palm applications DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) { // Variable declarations EventType event; // Check the launch code if (cmd == sysAppLaunchCmdNormalLaunch) { // Initialise the application if (0 == StartApplication()) { do { // Wait until something happens EvtGetEvent(&event, evtWaitForever); // Let the system handle the event if (!SysHandleEvent(&event)) { // Check if the form was changed if (!ApplicationHandleEvent(&event)) { // Handle events for the current form FrmDispatchEvent(&event); } } // Quit if we have received an appStopEvent } while (event.eType != appStopEvent); StopApplication(); } } // cmd == sysAppLaunchCmdNormalLaunch return; } // PilotMain |
Four extra functions are implemented. StartApplication which initializes the application when it's started, StopApplication terminates the application. When the mainframe is opened, it gets drawn by the function MainFormHandleEvent. The mainframe becomes active by the ApplicationHandleEvent function.
PilotMain has also changed a bit. First, the WinDrawChars function is removed. Drawing the frame is handled by the MainFormHandleEvent function. Second, the StartApplication and StopApplicaton functions are called at the appropriate places. And last, the event loop was extended. Exept for handling system events, the ApplicationHandleEvent function gets a chance to handle the loading of the forms, and the MainFormHandleEvent function to handle the events generated by the MainForm
the application now looks like this when executed:
The application screen with the Hello world application |
Toni Cornelissen 13 September 2004 toni@dse.nl |
Daily horoscope |