PALM开发教程-第十二章 专业编程技巧 |
| 作者:palmheart 来源:palmheart.net 发布时间:2005-12-21 3:39:54 |
|
------------------------------------------------ EventPtr spEvent ) //---------------------------------------------------------------------------- { // Handle the event switch( spEvent->eType ) { // A control was selected case ctlSelectEvent: // Return to the calling form FrmReturnToForm( 0 ); return( false ); // A menu item was selected case menuEvent: // Handle the menu event prefsFormMenuEventHandler( spEvent ); return( true ); } // We're done return( false ); } fprefs.h模块 此头文件和calc和about的头文件基本上是一致的,拷贝fabout.h并将其重命名为fprefs.h。将其添加到工程中并放置在AppIncludes下面。下面是所要做的修改: #ifndef FPREFS_H #define FPREFS_H ////////////////////////////////////////////////////////////////////////////// // fprefs.h // Definitions for the "prefs" form. // Copyright (c) 1999, Robert Mykland. All rights reserved. ////////////////////////////////////////////////////////////////////////////// /////////////////////// // Global Prototypes // /////////////////////// Boolean prefsFormEventHandler( EventPtr spEvent ); #endif // FPREFS_H moptions.c模块 Options菜单的源代码也只有一个事件处理函数。从源文件中任意拷贝一个.c文件,并添加到AppSource下的工程中,根据下面代码列表做相应的修改: ////////////////////////////////////////////////////////////////////////////// // moptions.c // Code for the "options" menu. // Copyright (c) 1999, Robert Mykland. All rights reserved. ////////////////////////////////////////////////////////////////////////////// ////////////// // Includes // ////////////// #include "app.h" // The definitions for this application /////////////////////// // Global Prototypes // /////////////////////// Boolean optionsMenuEventHandler( EventPtr spEvent ); ////////////////////// // Global Functions // ////////////////////// //---------------------------------------------------------------------------- Boolean optionsMenuEventHandler( //---------------------------------------------------------------------------- // Handles events for this form. // Returns true if it fully handled the event. //---------------------------------------------------------------------------- EventPtr spEvent ) //---------------------------------------------------------------------------- { switch( spEvent->data.menu.itemID ) { // The about menu item was selected case OptionsAbout: FrmPopupForm( AboutForm ); return( true ); // The prefs menu item was selected case OptionsPreferences: FrmPopupForm( PrefsForm ); return( true ); } // We're done return( false ); } 当菜单项被选中后,我们调用FrmPopupForm()弹出相应的窗体。如果菜单项和窗体ID相符返回true,否则返回false。 Moptions.h模块 该头文件和以前的头文件也十分相似,只包含和一个事件处理函数的原型。将前面任意的一个头文件拷贝并重命名moptions.h,然后将其添加到AppIncludes下的工程中,相应的修改如下所示: #ifndef MOPTIONS_H #define MOPTIONS_H ////////////////////////////////////////////////////////////////////////////// // moptions.h // Definitions for the "options" menu. // Copyright (c) 1999, Robert Mykland. All rights reserved. ////////////////////////////////////////////////////////////////////////////// /////////////////////// // Global Prototypes // /////////////////////// Boolean optionsMenuEventHandler( EventPtr spEvent ); #endif // MOPTIONS_H app.h的内容添加 为了将新建的模块包含在app.h里面,我们需要添加一些代码,首先是新的头文件: ////////////// // Includes // ////////////// #include <Pilot.h> // All the Palm includes #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 将新建的头文件逐个添加到app.h中,我一般是按照字母的顺序来排列这些文件名,这样就可以很容易查找所需头文件。 ////////////////////////////// // Definitions for fabout.c // ////////////////////////////// // The menu event handler macro for the "about" form #define aboutFormMenuEventHandler(spEvent) ///////////////////////////// // Definitions for fcalc.c // ///////////////////////////// // The menu event handler macro for the "calc" form #define calcFormMenuEventHandler(spEvent) \ {\ optionsMenuEventHandler( spEvent );\ } fabout.c和fpref.c所需要的程序入口和fcalc.c相似。然后为各自的菜单添加相应的宏。另外,由于我们添加了菜单,所以菜单处理宏也应该干点什么了。在宏中我们调用了函数optionMenuEventHandler()来处理该菜单的各个选项。 下面向getEventHandler()函数添加代码,以使我们新建的窗体能够被引发。 // This creates the function getEventHandler, // which returns the event handler for a given form // in this application. #define EVENT_HANDLER_LIST \ static FormEventHandlerPtr getEventHandler( Word wFormID )\ {\ switch( wFormID )\ {\ case AboutForm:\ return( aboutFormEventHandler );\ case CalcForm:\ return( calcFormEventHandler );\ case PrefsForm:\ return( prefsFormEventHandle |
| [] [返回上一页] [打 印] |
|
文章评论 |
