这个不用讲吧?写的很清楚的嘛。
[quote]koodoo 写道:
谁把这个讲解一下
A "HelloWorld" that compiles in both worlds
Studying the source code of this skeletal program is a good way to learn about the Palm OS. This source code is an adaptation of a HelloWorld by Wayne Tyler that I learned a great deal from, so I hope this well help you in the same way. I have added a menu to Wayne's version and made the modifications discussed above so that it will compile in CodeWarrior. I have done my best to annotate the code with accurate descriptions of what is happening, but a more experienced Palm programmer might correct me on certain points. So don't treat it as something handed down from the sky on stone tablets!
Listing 1: HelloWorld.c
//Ask the preprocessor if it belongs to CW and tell it
//to use the system header instead of OnBoardHeader.h
//if it does. OnBoardC's preprocessor will ignore this
//and automatically include OnBoardHeader.h
#define OnBoardC 1
#ifdef __MWERKS__
#undef OnBoardC
#include
#endif
//The prototypes (required by CW) are in a separate
//header file. OBC doesn't need them, but they force
//you to mind your types and write good code.
#include "HelloWorld.h"
//Tell the preprocessor to find-n-replace these
//friendly names for the resources with the IDs
//assigned them by RsrcEdit, Constructor, or PilRC.
#define OptionsMenuAbout 1000
#define AboutAlert 1000
#define frmMain 1000
//PilotMain() is where everything begins and ends
//in every Palm app. It's recognized by the compiler,
//which is why you don't need to prototype it.
UInt32 PilotMain( UInt16 cmd, void *cmdPBP, UInt16 launchFlags )
{
//This simple app only uses the first of the three
//parameters, so CW warns you unless you use these
//pragmas to tell it this is acceptable for now.
#ifdef __MWERKS__
#pragma unused(cmdPBP)
#pragma unused(launchFlags)
#endif
Err error;
switch( cmd ) //What launch code is coming in?
{
//Normal launch, e.g. from tapping the app icon
case sysAppLaunchCmdNormalLaunch:
error = StartApplication();
if( error )
return error;
//Start listening for events...
EventLoop();
//Event loop returned control to PilotMain
//upon receiving an appStopEvent.
StopApplication();
break;
//Other launch codes are ignored for now.
default:
break;
}
//Thank you for flying HelloWorld!
return 0;
}
static UInt16 StartApplication( void )
{
//Load and open our form
FrmGotoForm( frmMain );
return 0;
}
//Start listening for events and sending
//them to the appropriate event handlers
static void EventLoop( void )
{
Err error;
EventType event;
do //Keep listening until appStopEvent arrives
{
//Get the next event from the queue
EvtGetEvent( &event, evtWaitForever );
//Send event to system for handling first
if( !SysHandleEvent( &event ))
{
//Not a system event, so send to menu handler
if( !MenuHandleEvent( 0, &event, &error ))
{
//Not a menu event, so send to the app
//event handler that you created below
if( !ApplicationHandleEvent( &event ) )
//Event still not completely handled so
//pass it to the app's form event handler
FrmDispatchEvent( &event );
}
}
}
while( event.eType != appStopEvent );
}
static void StopApplication( void )
{
//Like it says: close all forms.
FrmCloseAllForms();
}
static Boolean ApplicationHandleEvent( EventPtr event )
{
UInt16 formID;
FormPtr form;
Boolean handled = false;
switch( event->eType )
{
//Add as many cases as you need to handle each possible
//event that your expanding application must handle.
//This simple one only needs two.
case frm