Home Hobby Work Code WWW
wmail Palm route newpic zeef Euro
Tutorial RSI Clock Convert
prevtocnextindex

Menu

The next gadget we're going to add to our application is a menu. A menu is also added to the resource file:
helloworld.rcp
#include "helloworld_rcp.h"

VERSION "2.2"
ICON "../resources/icon.bmp"
SMALLICON "../resources/icon_s.bmp"

// The menu
MENU ID MainMenuBar
BEGIN
  PULLDOWN "Hello World"
  BEGIN
    MENUITEM "About" HelloAboutMenuItem
  END
END

// The main form
FORM ID MainForm AT (0 0 160 160)
NOFRAME
USABLE
MENUID MainMenuBar
BEGIN
  TITLE "Hello world"
  BUTTON "Hello" ID MainHelloButton AT (50 140 60 15) USABLE FRAME FONT 0
END

The menu is defined to have only one PULLDOWN and that puldown has only one MENUITEM. This menu is added to the MainForm with the MENUID.

And as usual the identifiers are defined in the helloworld_rcp.h-file:

helloworld_rcp.h
// Defines for the Hello world application
#define MainForm             1000
#define MainHelloButton      1010

#define MainMenuBar          2000
#define HelloAboutMenuItem   2010

The code to handle menu events is added to the event loop:

helloworld.c
#include "helloworld.h"

// Initialises the application
Boolean StartApplication(void)
{
  // Start the main form
  FrmGotoForm(MainForm);
  return false;
} // StartApplication

// terminates the application
void StopApplication(void) {
  FrmCloseAllForms();
} // StopApplication

// Entry point for palm applications
DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) {
  // Variable declarations
  EventType event;
  Word      error;       

  // 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)) {
          // Menu events     
          if (!MenuHandleEvent(0, &event, &error)) {
            // 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 

When the menu in the application is selected, it looks like this:

The menu
The menu

prevtocnextindex
Tutorial RSI Clock Convert
wmail Palm route newpic zeef Euro
Home Hobby Work Code WWW

Toni Cornelissen
13 September 2004
toni@dse.nl
Lid van de Technetium groep
Daily horoscope NetStat W3C Validator