Programming for Palm OS/C/Menus

files

edit

With all of these files in the working directory, invoke:

make -f MenusMakefile

..which will create Menus.prc in the working directory ready for installation on a Palm.


edit

This file defines in one place constants that are referred to by both Menus.rcp and Menus.c.


#define  MainForm            1000
#define  MainMenu            1000
#define  MainMenuRecordNew   1011
#define  MainMenuRecordOpen  1012
#define  MainMenuHelpAbout   1020

edit

#include "Menus.h"

MENU ID MainMenu
BEGIN
  PULLDOWN "Record"
  BEGIN
    MENUITEM "New" ID MainMenuRecordNew "N"
    MENUITEM SEPARATOR
    MENUITEM "Open" ID MainMenuRecordOpen "O"
  END
  PULLDOWN "Help"
  BEGIN
    MENUITEM "About" ID MainMenuHelpAbout "A"
  END
END

FORM ID MainForm AT (0 0 160 160)
USABLE
MENUID MainMenu
BEGIN
END


edit

#include <PalmOS.h>
#include <unix_stdarg.h>
#include "Menus.h"


void showMessage( char *format, ...)
{
  va_list  args;
  char     msg[99];

  va_start( args, format);
  StrVPrintF( msg, format, args);
  va_end( args);

  WinDrawChars( msg, StrLen(msg), 0, 80);
}


Boolean appHandleEvent( EventPtr event)
{
  Boolean  handled;
  FormPtr  form;

  handled = true;

  if ( frmLoadEvent == event->eType)
  {
    form = FrmInitForm( event->data.frmLoad.formID);
    FrmSetActiveForm( form);
  }
  else if ( menuEvent == event->eType)
  {
    showMessage( "selected resource %i", event->data.menu.itemID);
  }
  else {
    handled = false;
  }

  return handled;
}


UInt32 PilotMain( UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
{
  EventType  event;
  UInt16     error;

  if ( sysAppLaunchCmdNormalLaunch == cmd)
  {
    FrmGotoForm( MainForm);

    showMessage( "open the menu");

    do {
      EvtGetEvent( &event, evtWaitForever);

      if ( ! SysHandleEvent( &event))
      if ( ! MenuHandleEvent( 0, &event, &error))
      appHandleEvent( &event);

    } while (event.eType != appStopEvent);

    FrmCloseAllForms();
  }

  return 0;
}


edit

PROJECT=Menus
CREATOR_ID=Anon

.SILENT:

all: $(PROJECT).prc

$(PROJECT).prc: $(PROJECT).c $(PROJECT).h $(PROJECT).rcp
	m68k-palmos-gcc $(PROJECT).c -o $(PROJECT)
	m68k-palmos-obj-res $(PROJECT)
	pilrc -q $(PROJECT).rcp
	build-prc $(PROJECT).prc "$(PROJECT)" $(CREATOR_ID) *.$(PROJECT).grc *.bin
	rm *.$(PROJECT).grc *.bin $(PROJECT)

clean:
	rm -f $(PROJECT).prc