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:36:55

static Int sortBy;
// CH.7 NOTE: These items match the popup list entries!
#define SORTBY_DATE_TIME 0
#define SORTBY_FIRST_NAME 1
#define SORTBY_LAST_NAME 2

// CH.8 Table constants
#define TABLE_NUM_COLUMNS 3
#define TABLE_NUM_ROWS 11
#define TABLE_COLUMN_DATE 0
#define TABLE_COLUMN_TIME 1
#define TABLE_COLUMN_NAME 2
#define BLACK_UP_ARROW "\x01"
#define BLACK_DOWN_ARROW "\x02"
#define GRAY_UP_ARROW "\x03"
#define GRAY_DOWN_ARROW "\x04"

// CH.9 Category variables
static Word listCat = dmAllCategories; // CH.9 The current category ID
static Word detailCat; // CH.9 Category ID for details
static UInt tableIndex[TABLE_NUM_ROWS]; // CH.9 Record indexes for rows

// CH.9 Goto variable
static Boolean upStack;

// CH.2 The main entry point
DWord PilotMain( Word cmd, Ptr params, Word )
{
DWord romVersion; // CH.4 ROM version
LocalID dbID; // CH.9 Local ID of the database
UInt cardNum; // CH.9 Card number
LocalID appInfoID; // CH.9 Local ID of the app info block
VoidHand hAppInfo; // CH.9 Handle to the app info block
AppInfoPtr pAppInfo; // CH.9 Points to the app info block
FormPtr form; // CH.2 A pointer to our form structure
EventType event; // CH.2 Our event structure
Word error; // CH.3 Error word

// CH.4 Get the ROM version
romVersion = 0;
FtrGet( sysFtrCreator, sysFtrNumROMVersion, &romVersion );

// CH.4 If we are below our minimum acceptable ROM revision
if( romVersion < ROM_VERSION_MIN )
{
// CH.4 Display the alert
FrmAlert( LowROMVersionErrorAlert );

// CH.4 PalmOS 1.0 will continuously re-launch this app
// unless we switch to another safe one
if( romVersion < ROM_VERSION_2 )
{
AppLaunchWithCommand( sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL );
}
return( 0 );
}

// CH.9 Respond to launches
switch( cmd )
{
// CH.2 Normal launch
case sysAppLaunchCmdNormalLaunch:
break;

// CH.9 System find
case sysAppLaunchCmdFind:
find( params );
return( 0 );

// CH.9 Go to item from find
case sysAppLaunchCmdGoT
break;

// CH.2 We don't handle what's being asked for
default:
return( 0 );
}

// CH.5 Create a new database in case there isn't one
if( ((error = DmCreateDatabase( 0, "ContactsDB-PPGU", 'PPGU', 'ctct',
false )) != dmErrAlreadyExists) && (error != 0) )
{
// CH.5 Handle db creation error
FrmAlert( DBCreationErrorAlert );
return( 0 );
}

// CH.9 Open the database if it isn't already open
if( contactsDB == NULL )
{
contactsDB = DmOpenDatabaseByTypeCreator( 'ctct', 'PPGU',
dmModeReadWrite );
}
else
upStack = true;

// CH.9 Get the ID and card number
DmOpenDatabaseInfo( contactsDB, &dbID, NULL, NULL, &cardNum, NULL);

// CH.9 Get the app info pointer if any
DmDatabaseInfo( cardNum, dbID, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, &appInfoID, NULL, NULL, NULL );



// CH.5 Get the number of records in the database
numRecords = DmNumRecords( contactsDB );

// CH.5 Initialize the record number
cursor = 0;

// CH.7 Choose our starting page
// CH.5 If there are no records, create one
if( numRecords == 0 )
{
newRecord();
FrmGotoForm( ContactDetailForm );
}

else
// CH.9 We are going to a particular record
if( cmd == sysAppLaunchCmdGoTo )
{
// CH.9 In case our app was running before the find
FrmCloseAllForms();

// CH.9 Point the cursor to the found item
cursor = ((GoToParamsPtr)params)->recordNum;

// CH.9 Go to the details page
FrmGotoForm( ContactDetailForm );

// CH.9 If we are running on top of ourselves,
// return to the original event loop
if( upStack )
{
upStack = false;
return( 0 );
}
}

else
// CH.7 Display the list
FrmGotoForm( ContactListForm );

// CH.7 Begin the try block
ErrTry {

// CH.2 Our event loop
do
{
// CH.2 Get the next event
EvtGetEvent( &event, -1 );

// CH.2 Handle system events
if( SysHandleEvent( &event ) )
continue;

// CH.3 Handle menu events
if( MenuHandleEvent( NULL, &event, &error ) )
continue;

// CH.4 Handle form load events
if( event.eType == frmLoadEvent )
{
// CH.4 Initialize our form
switch( event.data.frmLoad.formID )
{
// CH.4 Contact Detail form
case ContactDetailForm:
form = FrmInitForm( ContactDetailForm );
FrmSetEventHandler( form, contactDetailHandleEvent );
break;

// CH.4 About form
case AboutForm:
form = FrmInitForm( AboutForm );
FrmSetEventHandler( form, aboutHandleEvent );
break;

// CH.6 Enter Time form
case EnterTimeForm:
form = FrmInitForm( EnterTimeForm );
FrmSetEventHandler( form, enterTimeHandleEvent );
break;

// CH.7 Contact List form
case ContactListForm:
form = FrmInitForm( ContactListForm );
FrmSetEventHandler( form, contactListHandleEvent );
break;
}
FrmSetActiveForm( form );
}

// CH.2 Handle form events
FrmDispatchEvent( &event );

// CH.2 If it's a stop event, exit
} while( event.eType != appStopEvent );

// CH.7 End the try block and do the catch block
}
ErrCatch( errorAlert )
{
// CH.7 Display the appropriate alert
FrmAlert( errorAlert );
} ErrEndCatch

// CH.5 Close all open forms
FrmCloseAllForms();

// CH.5 Close the database
DmCloseDatabase( conta

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

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

用户名: 查看更多评论

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

内 容:

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