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:33:26
rd hour;

// CH.6 Get the form
form = FrmGetActiveForm();

// CH.6 Get the control pointers
hourButton = getObject( form, EnterTimeHoursPushButton );
minuteTensButton = getObject( form,
EnterTimeMinuteTensPushButton );
minuteOnesButton = getObject( form,
EnterTimeMinuteOnesPushButton );
amButton = getObject( form, EnterTimeAMPushButton );
pmButton = getObject( form, EnterTimePMPushButton );
noTimeCheckbox = getObject( form, EnterTimeNoTimeCheckbox );

// CH.6 If there is a time
if( dateTime.hour != NO_TIME )
{
// CH.6 Update the hour
hour = dateTime.hour % 12;
if( hour == 0 )
hour = 12;
CtlSetLabel( hourButton,
StrIToA( labelString, hour ) );

// CH.6 Update the minute tens
CtlSetLabel( minuteTensButton,
StrIToA( labelString, dateTime.minute / 10 ) );

// CH.6 Update the minute ones
CtlSetLabel( minuteOnesButton,
StrIToA( labelString, dateTime.minute % 10 ) );

// CH.6 Update AM
CtlSetValue( amButton, (dateTime.hour < 12) );

// CH.6 Update PM
CtlSetValue( pmButton, (dateTime.hour > 11) );

// CH.6 Uncheck the no time checkbox
CtlSetValue( noTimeCheckbox, false );
}

else
// If there is no time
{
// CH.6 Update the hour
CtlSetValue( hourButton, false );
CtlSetLabel( hourButton, "" );

// CH.6 Update the minute tens
CtlSetValue( minuteTensButton, false );
CtlSetLabel( minuteTensButton, "" );

// CH.6 Update the minute ones
CtlSetValue( minuteOnesButton, false );
CtlSetLabel( minuteOnesButton, "" );

// CH.6 Update AM
CtlSetValue( amButton, false );

// CH.6 Update PM
CtlSetValue( pmButton, false );

// CH.6 Uncheck the no time checkbox
CtlSetValue( noTimeCheckbox, true );
}

// CH.6 We're done
return;
}

// CH.7 Builds the contact list
static void buildList( void )
{
FormPtr form; // CH.6 A form structure pointer
Int choice; // CH.7 The list choice we're doing
CharPtr precord; // CH.7 Pointer to a record
Char listChoice[dateStringLength + 1 + // CH.7 We
timeStringLength + 1 + // build
DB_FIRST_NAME_SIZE + // list
DB_LAST_NAME_SIZE]; // choices here
// CH.7 The current list choice
CharPtr pchoices; // CH.7 Pointer to packed choices
UInt offset; // CH.7 Offset into packed strings
VoidPtr ppchoices; // CH.7 Pointer to pointers to choices

// CH.6 Get our form pointer
form = FrmGetActiveForm();

// CH.7 Put the list choices in a packed string
for( choice = 0; choice < numRecords; choice++ )
{
// CH.7 Get the record
hrecord = DmQueryRecord( contactsDB, choice );
precord = MemHandleLock( hrecord );

// CH.7 Get the date and time
MemMove( &dateTime, precord + DB_DATE_TIME_START,
sizeof( dateTime ) );

// CH.7 Clear the list choice string
*listChoice = '\0';

// CH.7 Add the date string if any
if( dateTime.year != NO_DATE )
{
DateToAscii( dateTime.month, dateTime.day,
dateTime.year,
(DateFormatType)PrefGetPreference(
prefDateFormat ), listChoice );
StrCat( listChoice, " " );
}

// CH.7 Add the time string if any
if( dateTime.hour != NO_TIME )
{
TimeToAscii( dateTime.hour, dateTime.minute,
(TimeFormatType)PrefGetPreference(
prefTimeFormat ), listChoice +
StrLen( listChoice ) );
StrCat( listChoice, " " );
}

// CH.7 Append the first name
StrCat( listChoice, precord + DB_FIRST_NAME_START );
StrCat( listChoice, " " );

// CH.7 Append the last name
StrCat( listChoice, precord + DB_LAST_NAME_START );

// CH.7 Allocate memory for the list entry string
// CH.7 If this is the first choice
if( hchoices == 0 )
{
// CH.7 Allocate the storage for the choice
if( (hchoices = MemHandleNew(
StrLen( listChoice ) + 1 )) == 0 )
errorExit( MemoryErrorAlert );

// CH.7 Initial offset points to the start
offset = 0;
}

else
// CH.7 If this is a subsequent choice
{
// CH.7 Unlock
MemHandleUnlock( hchoices );

// CH.7 Resize
if( MemHandleResize( hchoices, offset +
StrLen( listChoice ) + 1 ) )
errorExit( MemoryErrorAlert );

}

// CH.7 Lock
pchoices = MemHandleLock( hchoices );

// CH.7 Copy the string into the memory
StrCopy( pchoices + offset, listChoice );
offset += StrLen( listChoice ) + 1;

// CH.7 Unlock the record
MemHandleUnlock( hrecord );
}

// CH.7 Create a pointer array from the packed string list
if( (hpchoices = SysFormPointerArrayToStrings( pchoices,
numRecords )) == 0 )
errorExit( MemoryErrorAlert );
ppchoices = MemHandleLock( hpchoices );

// CH.7 Set the list choices
LstSetListChoices( getObject( form, ContactListListList ),
ppchoices, numRecords );

// CH.7 Draw the list
LstDrawList( getObject( form, ContactListListList ) );

// CH.7 We're done
return;
}

// CH.7 This function is called by Palm OS to sort records
static Int sortFunc( CharPtr precord1, CharPtr precord2, Int sortBy )
{
Int sortResult;

// CH.7 Switch based on sort criteria
switch( sortBy )
{
// CH.7 Sort by date and time
case SORTBY_DATE_TIME:
{
DateTimePtr pdateTime1;
DateTimePtr pdateTime2;
Long lDiff;

pdateTime1 = (DateTimePtr)(precord1 + DB_DATE_TIME_START);
pdateTime2 = (DateTimePtr)(precord2 + DB_DATE_TIME_START);

// CH.7 Compare the dates and times
lDiff = (Long)(TimDateTimeToSeconds( pdateTim

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

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

用户名: 查看更多评论

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

内 容:

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