⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 CD_《Palm OS编程实践》
💻 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 menu bar pointer
static MenuBarPtr spMenuBar;

// 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 );
		
		// PalmOS 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 );

	ErrTry
	{
		// Initialize all parts of the application
		appInit();

		// Go to the starting form
		FrmGotoForm( StartForm );
	
		// Wait indefinitely for events
		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 stop event, exit
	if( sEvent.eType == appStopEvent )
	{
		// Exit
		ErrThrow( 0 );
	}

	// 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( spMenuBar, &sEvent, &wError ) )
		return( true );

	// Load a form
	if( sEvent.eType == frmLoadEvent )
	{
		Word	wFormID;	// The form ID
		FormPtr	spForm;		// Points to the form

		// Kill the previous menu if any
		if( spMenuBar )
		{
			MenuDispose( spMenuBar );
			spMenuBar = NULL;
		}

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

		// Set the menu if any
		if( spForm->menuRscId )
			spMenuBar = MenuInit( spForm->menuRscId );
	}

	// Handle form events
	FrmDispatchEvent( &sEvent );

	// We're done
	return( true );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -