PALM开发教程-第十二章 专业编程技巧 |
| 作者:palmheart 来源:palmheart.net 发布时间:2005-12-21 3:39:54 |
|
/////////////////////// // Definitions for fprefs.c // ////////////////////////////// // The menu event handler macro for the "prefs" form #define prefsFormMenuEventHandler(spEvent) //////////////////////////// // Definitions for main.c // //////////////////////////// // The prototype for getEventHandler() static FormEventHandlerPtr getEventHandler( Word ); // 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( prefsFormEventHandler );\ }\ return( NULL );\ } // This defines the macro that initializes the app #define appInit() // This defines the macro that cleans up the app #define appStop() // This application works on PalmOS 2.0 and above #define ROM_VERSION_MIN ROM_VERSION_2 // Define the starting form #define StartForm CalcForm //////////////////////////////// // Definitions for moptions.c // //////////////////////////////// // Menu ID name conversions #define OptionsAbout OptionsAboutCalculator #endif // APP_H 下面是main.c全部的源代码: ////////////////////////////////////////////////////////////////////////////// // main.c // Main entry point and event loop. // Copyright (c) 1999, Robert Mykland. All rights reserved. ////////////////////////////////////////////////////////////////////////////// ////////////// // Includes // ////////////// #include "app.h" // The definitions for this application /////////////////////// // Global Prototypes // /////////////////////// DWord PilotMain( Word, Ptr, Word ); // Main entry point. Boolean processEvent( Long ); // Processes the next event. ///////////////////// // Local Variables // ///////////////////// // The event handler list EVENT_HANDLER_LIST ////////////////////// // Global Functions // ////////////////////// //---------------------------------------------------------------------------- DWord PilotMain( //---------------------------------------------------------------------------- // The main entry point for this application. // Always returns zero. //---------------------------------------------------------------------------- Word wCmd, // The launch code Ptr, // The launch parameter block Word ) // The launch flags //---------------------------------------------------------------------------- { DWord dROMVersion; // Get the ROM version dROMVersion = 0; FtrGet( sysFtrCreator, sysFtrNumROMVersion, &dROMVersion ); // Alert and bail if the ROM version is too low if( dROMVersion < ROM_VERSION_MIN ) { FrmAlert( LowROMVersionErrorAlert ); // Palm OS 1.0 will continuously re-launch this app unless we switch // to another safe one if( dROMVersion < ROM_VERSION_2 ) { AppLaunchWithCommand( sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL ); } return( 0 ); } // If this is not a normal launch, don't launch if( wCmd != sysAppLaunchCmdNormalLaunch ) return( 0 ); // Initialize all parts of the application appInit(); // Go to the starting form FrmGotoForm( StartForm ); // Wait indefinitely for events ErrTry { while( true ) processEvent( -1 ); } // Stop the application ErrCatch( lError ) { } ErrEndCatch // Clean up before exit appStop(); // We're done return( 0 ); } //---------------------------------------------------------------------------- Boolean processEvent( //---------------------------------------------------------------------------- // Waits for and processes the next event. // Returns false if the queue is empty. //---------------------------------------------------------------------------- Long lTimeout ) // Time to wait in 100ths of a second, -1 = forever //---------------------------------------------------------------------------- { EventType sEvent; // Our event Word wError; // The error word for the menu event handler // Get the next event EvtGetEvent( &sEvent, lTimeout ); // If it's a nil event, return queue empty if( sEvent.eType == nilEvent ) return( false ); // Handle system events if( SysHandleEvent( &sEvent ) ) return( true ); // Handle menu events if( MenuHandleEvent( NULL, &sEvent, &wError ) ) return( true ); // Load a form if( sEvent.eType == frmLoadEvent ) { Word wFormID; // The form ID FormPtr spForm; // Points to the form // Get the ID wFormID = sEvent.data.frmLoad.formID; // Initialize the form spForm = FrmInitForm( wFormID ); // Establish the event handler FrmSetEventHandler( spForm, getEventHandler( wFormID ) ); // Point events to our form FrmSetActiveForm( spForm ); // Draw the form FrmDrawForm( spForm ); } // Handle form events FrmDispatchEvent( &sEvent ); // If it's a stop event, exit if( sEvent.eType == appStopEvent ) { // Exit ErrThrow( 0 ); } // We're done return( true ); } 可重用的About窗体 在这一部分中,我们将向工程中添加两个窗体和 |
| [] [返回上一页] [打 印] |
|
文章评论 |
