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
caNumber );

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

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

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

// We're done
return;
}

这里将新字段拷入正在使用字段的内存块中。然后重新获得字段指针并刷新,这很象我们在frmOpenEvent中做的那样。
函数calcSignalError()

//----------------------------------------------------------------------------
void calcSignalError(
//----------------------------------------------------------------------------
// Signals an error.
//----------------------------------------------------------------------------
void )
//----------------------------------------------------------------------------
{
SndPlaySystemSound( sndError );
return;
}

为显示错误信息,我们调用了函数SndPlaySystemSound()来发出警告声音。此函数在Ref2.pdf中有定义。

Fcalc.h文件内容的添加
由于我们向fcalc.c文件添加了全局函数,为使它们可以被通用,必须在头文件fcalc.h中声明。下面是修改后的fcalc.h文件的内容:

#ifndef FCALC_H
#define FCALC_H
//////////////////////////////////////////////////////////////////////////////
// fcalc.h
// Definitions for the "calc" form.
// Copyright (c) 1999, Robert Mykland. All rights reserved.
//////////////////////////////////////////////////////////////////////////////

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

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

#endif // FCALC_H

和通常一样,这个文件包含了fcalc.c中全局函数的原型。
Calc.h模块
在下一章中我们将添加计算器运行的一般代码。在这里,创建一个头文件来定义这些函数。在这个头文件中,即使在程序不完整的情况下,也可以进行编译连接和调试。它使用了宏来代替一般意义上的函数。定义这些函数的另一个方法是建立一个新模块和函数,但在其中只添加一些测试代码(就象对calcDisplay()的调用一样)。

#ifndef CALC_H
#define CALC_H
//////////////////////////////////////////////////////////////////////////////
// calc.h
// Definitions for the generic calculation routines.
// Copyright (c) 1999, Robert Mykland. All rights reserved.
//////////////////////////////////////////////////////////////////////////////

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

void calcAdd( void ); // Queue an add operation
void calcAppend( int ); // Append a digit
void calcChangeSign( void ); // Change the sign of the entry
void calcClear( void ); // Clear/reset the calculator
void calcDivide( void ); // Queue a divide operation
void calcEquals( void ); // Finish the current operation
void calcExponent( void ); // Start gathering the exponent
void calcMultiply( void ); // Queue a multiply operation
void calcPoint( void ); // Start gathering the fraction
void calcSubtract( void ); // Queue a subtraction operation

//////////////////////
// Global Constants //
//////////////////////

#define MAX_NUMBER_SIZE 40

#endif // CALC_H

calc.c的函数在这里都给出了定义,它包括了为测试calcDisplay()需要的一系列函数定义。
app.h内容的添加

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

#include <Pilot.h> // All the Palm includes
#include "MathLib.h" // Definitions for MathLib
#include "Calculator_res.h" // Resource definitions
#include "fabout.h" // Definitions for the "about" form
#include "fcalc.h" // Definitions for the "calc" form
#include "fprefs.h" // Definitions for the "prefs" form
#include "main.h" // Definitions for the main entry point
#include "moptions.h" // Definitions for the "options" menu

这里我们又添加了库函数MathLib.h,它包含了MathLib函数的定义。

// This defines the macro that initializes the app
#define appInit() \
{\
calcInit();\
}

// This defines the macro that cleans up the app
#define appStop() \
{\
calcStop();\
}

这里我们向appInit()和appStop()以前的空定义中添加了两个宏。如果模块需要初始化或扫尾都应向这些宏中添加函数调用。
安装MathLib
Mathlib是CD上一个自解压的可执行文件(MathLib.exe)。双击图标将其解压到一个目录下,并按下面步骤进行操作:
在解压的文件夹中,我们会发现我们使用MathLib所需的任何东西,包括HTML文档。将MathLib.c和MathLib.h拷到Calculatot工程的Src文件夹中。添加MathLib.c到工程里使之与库在一起,并确定它是一个基本的输入库。
我们还要为Palm装置安装MathLib.prc文件。用Palm Install Tool和HotSync可以完成,打开App | Info观察条目列表以确定传送是否成功。

当第一次测试程序时,为测试MathLibError警告信息是否工作,可以先不向Palm安装MathLib。
调试
下载并运行程序。按下不同的按钮测试函数calDisplay(),检查Done按钮能否顺利退出程序并且将当前的数字保存在剪贴板上。通过system preference改变千位符和小数点的值看它们是否可以从界面上反映出来。最后,看能否产生about窗体和prefs窗体。
下一步做什么
下一步我们将继续计算器程序的其它部分,学习怎样向Palm中添加一般的C代码。
程序列表
下面是fcalc.c的完整代码:
//////////////////////////////////////////////////////////////////////////////
// fcalc.c
// Code for the "calc" form.
/

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

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

用户名: 查看更多评论

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

内 容:

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