Slide 6.15: Event loop
  Slide 6.17: Line-by-line anatomy of Hello.c
  Home


The Hello-world Palm Program


The following program is the first Palm example, which simply prints the greeting “Hello, world!” .

 Hello.c 

// This header is from the Palm SDK and contains the needed reference
// materials for us to use the Palm API and its defined constants. 
#include  <PalmOS.h>

// ---------------------------------------------------------------------
// PilotMain is called by the startup code and implements a
// simple event handling loop.
// ---------------------------------------------------------------------

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

  if ( cmd == sysAppLaunchCmdNormalLaunch ) {
    //  Display a string.
    WinDrawChars( "Hello, world!", 13, 55, 60 );

    //  Main event loop:
    do {
      //  Doze until an event arrives.
      EvtGetEvent( &event, evtWaitForever );

      //  System gets first chance to handle the event.
      SysHandleEvent( &event );

      //  Normally, we would do other event processing here.
      //  Return from PilotMain when an appStopEvent is received.
    } while ( event.eType != appStopEvent );
  }
  return ( 0 );
}