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:41:03
/ Copyright (c) 1999, Robert Mykland. All rights reserved.
//////////////////////////////////////////////////////////////////////////////

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

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

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

void calcInit( void );
void calcStop( void );
Boolean calcFormEventHandler( EventPtr spEvent );
void calcDisplay( char* cpNumber );
void calcSignalError( void );

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

static char cComma; // The comma symbol we're using
static char cPoint; // The decimal point we're using
static Handle hNumber; // Handle to the number in our edit field

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

//----------------------------------------------------------------------------
void calcInit(
//----------------------------------------------------------------------------
// Initializes this module.
//----------------------------------------------------------------------------
void )
//----------------------------------------------------------------------------
{
DWord dChoice;
char* cpNumber;

// Find MathLib
if( (SysLibFind( MathLibName, &MathLibRef ) == 0) ||
SysLibLoad( LibType, MathLibCreator, &MathLibRef ) ||
MathLibOpen( MathLibRef, MathLibVersion ) )
{
FrmAlert( MathLibErrorAlert );
sendStopEvent();
}

// Allocate our field chunk
hNumber = MemHandleNew( MAX_NUMBER_SIZE );

// Lock the memory, get the pointer
cpNumber = MemHandleLock( hNumber );

// Initialize it
StrCopy( cpNumber, "0" );

// Unlock the field's memory
MemHandleUnlock( hNumber );

// Get the number format
dChoice = PrefGetPreference( prefNumberFormat );

// Handle the number format
switch( dChoice )
{
default:
cComma = ',';
cPoint = '.';
break;

case nfPeriodComma:
cComma = '.';
cPoint = ',';
break;

case nfSpaceComma:
cComma = ' ';
cPoint = ',';
break;

case nfApostrophePeriod:
cComma = '\'';
cPoint = '.';
break;

case nfApostropheComma:
cComma = '\'';
cPoint = ',';
break;
}

// We're done
return;
}

//----------------------------------------------------------------------------
void calcStop(
//----------------------------------------------------------------------------
// Cleans up stuff from this module.
//----------------------------------------------------------------------------
void )
//----------------------------------------------------------------------------
{
UInt uiUseCount;

// Close MathLib
MathLibClose( MathLibRef, &uiUseCount );
if( uiUseCount == 0 )
SysLibRemove( MathLibRef );

// Free the number field chunk
MemHandleFree( hNumber );

// We're done
return;
}

//----------------------------------------------------------------------------
Boolean calcFormEventHandler(
//----------------------------------------------------------------------------
// Handles events for this form.
// Returns true if it fully handled the event.
//----------------------------------------------------------------------------
EventPtr spEvent )
//----------------------------------------------------------------------------
{
// Handle the event
switch( spEvent->eType )
{
// The form is opened
case frmOpenEvent:
{
FormPtr spForm;
Word wIndex;
FieldPtr spField;
ControlPtr spButton;
char caPoint[2];

// Get the field
spForm = FrmGetActiveForm();
wIndex = FrmGetObjectIndex( spForm, calcNumberField );
spField = FrmGetObjectPtr( spForm, wIndex );

// Draw the field
FldSetTextHandle( spField, hNumber );
FldDrawField( spField );

// Get the decimal point button
wIndex = FrmGetObjectIndex( spForm, calcPointButton );
spButton = FrmGetObjectPtr( spForm, wIndex );

// Draw the decimal point button
caPoint[0] = cPoint;
caPoint[1] = '\0';
CtlSetLabel( spButton, caPoint );
}
break;

// A control was selected
case ctlSelectEvent:
{
// Handle the different buttons
switch( spEvent->data.ctlSelect.controlID )
{
case calcAddButton:
calcAdd();
break;

case calcChangesignButton:
calcChangeSign();
break;

case calcClearButton:
calcClear();
break;

case calcDivideButton:
calcDivide();
break;

case calcDoneButton:
{
char* cpNumber;

// Lock the memory, get the pointer
cpNumber = MemHandleLock( hNumber );

// Copy to the clipboard
ClipboardAddItem( clipboardText, cpNumber,
StrLen( cpNumber ) );

// Unlock the field's memory
MemHandleUnlock( hNumber );

// Exit the application
sendStopEvent();
}
break;

case calcEightButton:
calcAppend( 8 );
break;

case calcEqualsButton:
calcEquals();
break;

case calcExponentButton:
calcExponent();
break;

case calcFieldborderButton:
// Ignore this button
return( true );

case calcFiveButton:
calcAppend( 5 );
break;

case calcFourButton:
calcAppend( 4 );
break;

case calcMultiplyButton:
calcMultiply();
break;

case calcNineButton:
calcAppend( 9 );
break;

case calcOneButton:
calcAppend( 1 );
break;

case calcPointButton:
calcPoint();
break;

case calcSevenButton:
calcAppend( 7 );
break;

case calcS

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

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

用户名: 查看更多评论

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

内 容:

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