WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章手机编程PlamPALM开发教程-第十二章 专业编程技巧

PALM开发教程-第十二章 专业编程技巧
作者:palmheart  来源:palmheart.net  发布时间:2005-12-21 3:39:54
///////////////////////
// Definitions for fprefs.c //
//////////////////////////////

// The menu event handler macro for the "prefs" form
#define prefsFormMenuEventHandler(spEvent)

////////////////////////////
// Definitions for main.c //
////////////////////////////

// The prototype for getEventHandler()
static FormEventHandlerPtr getEventHandler( Word );

// This creates the function getEventHandler,
// which returns the event handler for a given form
// in this application.
#define EVENT_HANDLER_LIST \
static FormEventHandlerPtr getEventHandler( Word wFormID )\
{\
switch( wFormID )\
{\
case AboutForm:\
return( aboutFormEventHandler );\
case CalcForm:\
return( calcFormEventHandler );\
case PrefsForm:\
return( prefsFormEventHandler );\
}\
return( NULL );\
}

// This defines the macro that initializes the app
#define appInit()

// This defines the macro that cleans up the app
#define appStop()

// This application works on PalmOS 2.0 and above
#define ROM_VERSION_MIN ROM_VERSION_2

// Define the starting form
#define StartForm CalcForm

////////////////////////////////
// Definitions for moptions.c //
////////////////////////////////

// Menu ID name conversions
#define OptionsAbout OptionsAboutCalculator

#endif // APP_H

下面是main.c全部的源代码:

//////////////////////////////////////////////////////////////////////////////
// main.c
// Main entry point and event loop.
// Copyright (c) 1999, Robert Mykland. All rights reserved.
//////////////////////////////////////////////////////////////////////////////

//////////////
// Includes //
//////////////

#include "app.h" // The definitions for this application

///////////////////////
// Global Prototypes //
///////////////////////

DWord PilotMain( Word, Ptr, Word ); // Main entry point.
Boolean processEvent( Long ); // Processes the next event.

/////////////////////
// Local Variables //
/////////////////////

// The event handler list
EVENT_HANDLER_LIST

//////////////////////
// Global Functions //
//////////////////////

//----------------------------------------------------------------------------
DWord PilotMain(
//----------------------------------------------------------------------------
// The main entry point for this application.
// Always returns zero.
//----------------------------------------------------------------------------
Word wCmd, // The launch code
Ptr, // The launch parameter block
Word ) // The launch flags
//----------------------------------------------------------------------------
{
DWord dROMVersion;

// Get the ROM version
dROMVersion = 0;
FtrGet( sysFtrCreator, sysFtrNumROMVersion, &dROMVersion );

// Alert and bail if the ROM version is too low
if( dROMVersion < ROM_VERSION_MIN )
{
FrmAlert( LowROMVersionErrorAlert );

// Palm OS 1.0 will continuously re-launch this app unless we switch
// to another safe one
if( dROMVersion < ROM_VERSION_2 )
{
AppLaunchWithCommand( sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL );
}
return( 0 );
}

// If this is not a normal launch, don't launch
if( wCmd != sysAppLaunchCmdNormalLaunch )
return( 0 );

// Initialize all parts of the application
appInit();

// Go to the starting form
FrmGotoForm( StartForm );

// Wait indefinitely for events
ErrTry
{
while( true )
processEvent( -1 );
}

// Stop the application
ErrCatch( lError )
{
} ErrEndCatch

// Clean up before exit
appStop();

// We're done
return( 0 );
}

//----------------------------------------------------------------------------
Boolean processEvent(
//----------------------------------------------------------------------------
// Waits for and processes the next event.
// Returns false if the queue is empty.
//----------------------------------------------------------------------------
Long lTimeout ) // Time to wait in 100ths of a second, -1 = forever
//----------------------------------------------------------------------------
{
EventType sEvent; // Our event
Word wError; // The error word for the menu event handler

// Get the next event
EvtGetEvent( &sEvent, lTimeout );

// If it's a nil event, return queue empty
if( sEvent.eType == nilEvent )
return( false );

// Handle system events
if( SysHandleEvent( &sEvent ) )
return( true );

// Handle menu events
if( MenuHandleEvent( NULL, &sEvent, &wError ) )
return( true );

// Load a form
if( sEvent.eType == frmLoadEvent )
{
Word wFormID; // The form ID
FormPtr spForm; // Points to the form

// Get the ID
wFormID = sEvent.data.frmLoad.formID;

// Initialize the form
spForm = FrmInitForm( wFormID );

// Establish the event handler
FrmSetEventHandler( spForm, getEventHandler( wFormID ) );

// Point events to our form
FrmSetActiveForm( spForm );

// Draw the form
FrmDrawForm( spForm );
}

// Handle form events
FrmDispatchEvent( &sEvent );

// If it's a stop event, exit
if( sEvent.eType == appStopEvent )
{
// Exit
ErrThrow( 0 );
}

// We're done
return( true );
}

可重用的About窗体
在这一部分中,我们将向工程中添加两个窗体和

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  下一页

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码