手机操盘手免费体验火热进行
20万人已抢先免费使用
624MHz CPU极速智能HKC G920震憾登场
夏新智能手机专区
主流智能手机音乐播放软件横向评测 最新手机电影
发新话题
打印

[编程] OnBoardC新手入门

这个不用讲吧?写的很清楚的嘛。

[quote]koodoo 写道:
谁把这个讲解一下
A "HelloWorld" that compiles in both worlds
Studying the source code of this skeletal program is a good way to learn about the Palm OS. This source code is an adaptation of a HelloWorld by Wayne Tyler that I learned a great deal from, so I hope this well help you in the same way. I have added a menu to Wayne's version and made the modifications discussed above so that it will compile in CodeWarrior. I have done my best to annotate the code with accurate descriptions of what is happening, but a more experienced Palm programmer might correct me on certain points. So don't treat it as something handed down from the sky on stone tablets!

Listing 1: HelloWorld.c
//Ask the preprocessor if it belongs to CW and tell it
//to use the system header instead of OnBoardHeader.h
//if it does. OnBoardC's preprocessor will ignore this
//and automatically include OnBoardHeader.h
#define OnBoardC 1
#ifdef __MWERKS__
        #undef OnBoardC
        #include
#endif

//The prototypes (required by CW) are in a separate
//header file. OBC doesn't need them, but they force
//you to mind your types and write good code.
#include "HelloWorld.h"

//Tell the preprocessor to find-n-replace these
//friendly names for the resources with the IDs
//assigned them by RsrcEdit, Constructor, or PilRC.
#define OptionsMenuAbout 1000
#define AboutAlert 1000
#define frmMain    1000

//PilotMain() is where everything begins and ends
//in every Palm app. It's recognized by the compiler,
//which is why you don't need to prototype it.
UInt32 PilotMain( UInt16 cmd, void *cmdPBP, UInt16 launchFlags )
{
    //This simple app only uses the first of the three
    //parameters, so CW warns you unless you use these
    //pragmas to tell it this is acceptable for now.
    #ifdef __MWERKS__
        #pragma unused(cmdPBP)
        #pragma unused(launchFlags)
    #endif
   
    Err error;

    switch( cmd ) //What launch code is coming in?
    {
        //Normal launch, e.g. from tapping the app icon
        case sysAppLaunchCmdNormalLaunch:
            error = StartApplication();
            if( error )
                return error;

            //Start listening for events...
            EventLoop();

            //Event loop returned control to PilotMain
            //upon receiving an appStopEvent.
            StopApplication();
            break;
        //Other launch codes are ignored for now.
        default:
            break;
    }
    //Thank you for flying HelloWorld!
    return 0;
}

static UInt16 StartApplication( void )
{
    //Load and open our form
    FrmGotoForm( frmMain );
    return 0;
}

//Start listening for events and sending
//them to the appropriate event handlers
static void EventLoop( void )
{
    Err error;
    EventType event;

    do  //Keep listening until appStopEvent arrives
    {
        //Get the next event from the queue
        EvtGetEvent( &event, evtWaitForever );

        //Send event to system for handling first
        if( !SysHandleEvent( &event ))
        {
            //Not a system event, so send to menu handler
            if( !MenuHandleEvent( 0, &event, &error ))
            {
                //Not a menu event, so send to the app
                //event handler that you created below
                if( !ApplicationHandleEvent( &event ) )
                    //Event still not completely handled so
                    //pass it to the app's form event handler
                    FrmDispatchEvent( &event );
            }
        }
    }
    while( event.eType != appStopEvent );
}

static void StopApplication( void )
{
    //Like it says: close all forms.
    FrmCloseAllForms();
}

static Boolean ApplicationHandleEvent( EventPtr event )
{
    UInt16 formID;
    FormPtr form;
    Boolean handled = false;

    switch( event->eType )
    {
        //Add as many cases as you need to handle each possible
        //event that your expanding application must handle.
        //This simple one only needs two.
        case frm
http://cn.akeysoft.com(中文)
http://www.akeysoft.com(英文)
http://www.akeysoft.com/blog(个人BLOG)
http://www.viathink.com(公司网站)
引用:
zcj1122 写道:

另外,我想问问dumm大侠,看什么书入门呀?我发现palm上的c语言和pc上的很不一样,如没有main()、、(这个问题是不是很弱稚呀)你开发palm程序多长时间了?
看文档和范例入门比较快(当然前提要有C语言开发基础和OS的知识,没有就先补课)。

用PilotMain,请看文档和教程。

一年多吧。

http://cn.akeysoft.com(中文)
http://www.akeysoft.com(英文)
http://www.akeysoft.com/blog(个人BLOG)
http://www.viathink.com(公司网站)

最后补充一点东西

学习OnBoardC最好的方法是参加OnBoardC的讨论组和阅读文档。

如果没有Palm开发基础,先从CW或者GCC开发Palm程序开始学起,入门比较快。如果没有C语言开发基础,则应该先学C语言。如果对操作系统理论比较熟悉,学习PalmOS开发会很容易。

OnBoardC的讨论组在http://groups.yahoo.com/groups/onboardc

最后一点:努力提高英文阅读水平,否则很难学习软件开发技术。

http://cn.akeysoft.com(中文)
http://www.akeysoft.com(英文)
http://www.akeysoft.com/blog(个人BLOG)
http://www.viathink.com(公司网站)
在onBoradC自动生成的代码中有appHandleEvent()和mainFormEventHandler()这两个函数,在appHandleEvent函数里用
FrmSetEventHandler(frm,mainFormEventHandler)把mainFormEventHandler函数设置为主窗口的回调函数,可是我怎么没发现变量mainFormEventHandler在什么地方声明过??mainFormEventHandler只是一个函数名呀!!


palm是我的理想~~|~~|~~ plmm是我的梦想~~~_^^_~~~~ 为了理想而奋斗,为了梦想而追寻~~~:_:~~

这是函数指针

C语言的教材中应该有讲的。

http://cn.akeysoft.com(中文)
http://www.akeysoft.com(英文)
http://www.akeysoft.com/blog(个人BLOG)
http://www.viathink.com(公司网站)
dumm,我有两个很弱智的问题
FrmSetEventHandler函数的声明是:void FrmSetEventHandler(FormType *formP ,FormEventHandlerType *hander)为什么作为形参的hander没有说明他引用的函数的入口参数? 我认为应该是:void FrmSetEventHandler(FormType *formp,FormEventHandlerType (*hander)(EventPtr))
在onBoardC的cookbook的UI Objects: Lists 这一章中,有:        void LstDrawList (ListType *listP) SYS_TRAP(sysTrapLstDrawList);这样的语句声明,请问声明的后半部分SYS_TRAP(sysTrapLstDrawList);是什么意思??





zcj1122 编辑于 2003-4-5 23:44:50
palm是我的理想~~|~~|~~ plmm是我的梦想~~~_^^_~~~~ 为了理想而奋斗,为了梦想而追寻~~~:_:~~
1、形参的定义在FormEventHandlerType中定义了的;(这是C语言基础知识)
2、这是PalmOS的系统调用;

http://cn.akeysoft.com(中文)
http://www.akeysoft.com(英文)
http://www.akeysoft.com/blog(个人BLOG)
http://www.viathink.com(公司网站)
我还是搞不明白:
在OnBoardHearer.h中是这样定义的:#define SYS_TRAP(x) ={0x4e4f,x}
那么函数void LstDrawList (ListType *listP) SYS_TRAP(sysTrapLstDrawList);
展开后不就是void LstDrawList (ListType *listP) ={0x4e4f,sysTrapLstDrawList} 这是什么东西~~~~
还有我也没发现sysTrapLstDrawList在哪儿定义过。
如果我自己想往OnBoardHearer.h中加一些原本没有的Palm API函数如:
void FrmHideObject(FormType *formp,UInt16 objIndex)是不是出了这个声明外,还要在他后面加个SYS_TRAP(?????),到底该怎么办呀??

palm是我的理想~~|~~|~~ plmm是我的梦想~~~_^^_~~~~ 为了理想而奋斗,为了梦想而追寻~~~:_:~~
另外,当我用RsrcEdit设计一个Form时,如果想在此Form中加一个Label标签,但这个标签中的字符在一行里显示不完,怎样加入换行符呢?(在编辑标签时用回车换不行,显示一个乱码),只能用两个标签代替吗?

palm是我的理想~~|~~|~~ plmm是我的梦想~~~_^^_~~~~ 为了理想而奋斗,为了梦想而追寻~~~:_:~~
:#define SYS_TRAP(x) ={0x4e4f,x}
是palm rom的系统调用入口号,palm 能认出所有如sysTrapLstDrawList,sysTrapStrPrintF...等格式的系统函数。你不要管它是怎么用的,需要在onboardC.h中加系统函数申明时就用此格式:void LstDrawList (ListType *listP) SYS_TRAP(sysTrapLstDrawList);

最好是看看CodeWarrior的.h文件里的系统函数如何申明的,一样的。



PilotMain 编辑于 2003-4-21 14:50:58
Built with OnboradC
发新话题