首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

PALM OS上的入门列子Hello world 02

PALM OS上的入门列子Hello world 02

# Dependency targets

hello.o: hello.c resource.h


---------------------------------------------------------------------

文件:resource.h

#define MainMenu 1000

#define HelpMenuAbout 1010

#define HelloForm 1100

#define AboutAlert 2000

-------------------------------------------------------------------


文件:hello.rcp

#include "resource.h"


VERSION ID 1 "1.00"


////////////////////////////////////////////////////////////////////////
// Main menu

MENU ID MainMenu
BEGIN
  PULLDOWN "Help"
  BEGIN
    MENUITEM "About..." ID HelpMenuAbout
  END
END


////////////////////////////////////////////////////////////////////////
// "Hello, world!" form

FORM HelloForm AT (0 0 160 160)
  MENUID MainMenu
  USABLE
BEGIN
  LABEL "Hello, world!" AUTOID AT (CENTER 50)
END


////////////////////////////////////////////////////////////////////////
// About box

ALERT ID AboutAlert
BEGIN
  TITLE "About..."
  MESSAGE "Hello, world! demo app\nVersion 1.00\n\nCopyright \251 2001\nYoyodyne, Inc.\n"
  BUTTONS "OK"
END


////////////////////////////////////////////////////////////////////////
// The program's icon

ICON "icon.bmp"


--------------------------------------------------------------------------------

文件:hello.c

/***********************************************************************
hello.c - Sample "Hello, world!" program for Palm OS. Build with
  PRC-Tools 2.0 and Palm OS SDK 3.5 or better.

Created 2001.02.04 by Warren Young
$Revision: 1.3 $ $Date: 2001/02/05 03:34:34 $

This program is hereby placed into the public domain.
***********************************************************************/

#include

#include "resource.h"


////////////////////////////////////////////////////////////////////////
// Globals

// Pointer to the currently-active form
static FormPtr gpForm;


//// StartApplication //////////////////////////////////////////////////
// Called when application is starting

static Err StartApplication()
{
  FrmGotoForm(HelloForm);
  return 0;
}


//// StopApplication ///////////////////////////////////////////////////
// Called when application is being shut down.

static void StopApplication()
{
  FrmCloseAllForms();
}


//// HelloFormEventHandler /////////////////////////////////////////////
// Handle events for the "Hello, world!" form.

Boolean HelloFormEventHandler(EventPtr event)
{
  Boolean handled = false;

  switch (event->eType) {
    case frmOpenEvent: {
      gpForm = FrmGetActiveForm();
      FrmDrawForm(gpForm);
      handled = true;
      break;
    }

    case frmCloseEvent:
      FrmEraseForm(gpForm);
      FrmDeleteForm(gpForm);
      gpForm = 0;
      handled = true;
      break;

    default:
      // -Wall warning eater: switch must handle all enum
      // elements.
      break;
  }

  return handled;
}


//// ApplicationEventHandler /////////////////////////////////////////////
// Handle global events, and pass form-specific events to each form's
// event handler.

static Boolean ApplicationEventHandler(EventPtr event)
{
  Boolean handled = false;

  switch (event->eType) {
    case frmLoadEvent: {
      FormPtr pForm = FrmInitForm(event->data.frmLoad.formID);
      FrmSetActiveForm(pForm);
      FrmSetEventHandler(pForm, HelloFormEventHandler);
      handled = true;
      break;
    }

    case menuEvent:
      switch (event->data.menu.itemID) {
        case HelpMenuAbout:
          FrmAlert(AboutAlert);
          break;
      }

      handled = true;
      break;

    default:
      // -Wall warning eater: switch must handle all enum
      // elements.
      break;
  }

  return handled;
}


//// EventLoop /////////////////////////////////////////////////////////
// Global event loop.

static void EventLoop()
{
  EventType event;
  UInt16 error;
  do {
    EvtGetEvent(&event, evtWaitForever);

    if (!SysHandleEvent(&event)) {
      if (!MenuHandleEvent(0, &event, &error)) {
        if (!ApplicationEventHandler(&event)) {
          FrmDispatchEvent(&event);
        }
      }
    }
  }
  while (event.eType != appStopEvent);
}


//// PilotMain /////////////////////////////////////////////////////////
// It all starts here...

UInt32 PilotMain(UInt16 launchCode, MemPtr cmdPBP, UInt16 launchFlags)
{
  Err err = 0;

  if (launchCode == sysAppLaunchCmdNormalLaunch) {
    if ((err = StartApplication()) == 0) {
      EventLoop();
      StopApplication();
    }
  }

  return err;
}

返回列表