跳转到内容

Palm OS/C/Menus 编程

来自维基教科书,开放的书籍,面向开放的世界

将所有这些文件放在工作目录中,调用

make -f MenusMakefile

.. 这将创建Menus.prc在工作目录中,准备好安装到 Palm 上。


此文件在一个地方定义了由Menus.rcpMenus.c.

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

[编辑 | 编辑源代码]
#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


#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;
}


[编辑 | 编辑源代码]
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

华夏公益教科书