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

📄 wx.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 2 页
字号:
		gWxData.rainHour / 10, gWxData.rainHour % 10,		gWxData.rainDay / 10, gWxData.rainDay % 10 );	CtlSetLabel ( GetObjectPtr ( MainPrecipitationLabel ), gWxDisplay.precipLabel );	// Draw the form	FrmDrawForm( frmP );	// Force an redraw	MainFormDraw( frmP );	}/*********************************************************************** * FUNCTION:    	MainFormDone * * DESCRIPTION: 	This routine cleans up after the Main form. * * RETURNED:    	nothing ***********************************************************************/static void MainFormDone(	FormPtr	frmP		// Pointer to the MainForm form){	if ( frmP != NULL )	{	// Insert application-specific code first// Then do this as the very last thing		FrmEraseForm	( frmP );		FrmDeleteForm	( frmP );	}}/*********************************************************************** * FUNCTION:    	MainFormDoMenuCommand * * DESCRIPTION: 	This routine handles menu commands. * * RETURNED:    	nothing ***********************************************************************/ static Boolean MainFormDoMenuCommand(	UInt16 	command			// The ID of menu command to do){	Boolean handled = false;	FormPtr frmP;	switch ( command )	{#if 0		case MainOptionsServer:			MenuEraseStatus ( 0 );			frmP = FrmInitForm ( ServerForm );			// Set field			FrmDoDialog ( frmP );			// Get field.			FrmDeleteForm ( frmP );			handled = true;			break;#endif		case MainOptionsWeb:			MenuEraseStatus ( 0 );			WWWPref( );			handled = true;			break;				case MainOptionsAboutWx:			MenuEraseStatus ( 0 );			frmP = FrmInitForm ( AboutForm );			FrmDoDialog ( frmP );			FrmDeleteForm ( frmP );			handled = true;			break;	}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormDoUpdateButton * * DESCRIPTION: 	This routine updates the weather data * * RETURNED:    	nothing ***********************************************************************/void MainFormDoUpdateButton(	FormPtr frmP){		MemHandle dataH;		Char *dataP;		Err anErr;				dataH = WWWFetch( (Char *)wxURL, &anErr );		if ( dataH )		{			dataP = MemHandleLock( dataH );			MainFormParseWxString( dataP );			MainFormUpdate( frmP );				MemHandleUnlock( dataH );			MemHandleFree( dataH );		}}/*********************************************************************** * FUNCTION:    	MainFormHandleEvent * * DESCRIPTION: 	This routine is the event handler for MainForm. * * RETURNED:    	true if the event is handled. ***********************************************************************/ Boolean MainFormHandleEvent(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){    Boolean 	handled = false;    FormPtr		frmP = FrmGetActiveForm ();	switch ( eventP->eType ) 	{	// Menu event - call MainFormDoMenuCommand to handle it.		case menuEvent:					handled = MainFormDoMenuCommand ( eventP->data.menu.itemID );			break;		case frmOpenEvent:				MainFormInit ( frmP );	// ***** WARNING  - falls thru to next case *****					case frmUpdateEvent:			FrmDrawForm ( frmP );			MainFormDraw( frmP );			handled = true;			break; 								case frmCloseEvent:			MainFormDone ( frmP );			handled = true;			break;					case keyDownEvent:			handled = true;			break;					case ctlSelectEvent:			if ( eventP->data.ctlSelect.controlID == MainUpdateButton )			{				MainFormDoUpdateButton( frmP );				handled = true;				break;			}				}	return handled;}/*********************************************************************** * FUNCTION:    	AppHandleEvent * * DESCRIPTION: 	Loads a form's resources and set its event handler. * * RETURNED:    	true if the event is handled. ***********************************************************************/ static Boolean AppHandleEvent(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){	    Boolean 	handled = false;	if ( eventP->eType == frmLoadEvent )	{	// Form load event--initialize the form and make it the active form.		UInt16 	formId = eventP->data.frmLoad.formID;		FormPtr	frmP = FrmInitForm ( formId );		FrmSetActiveForm ( frmP );// Set the event handler for the form.		switch (formId)		{			case MainForm:							FrmSetEventHandler(frmP, MainFormHandleEvent);				handled = true;				break;//	Insert other cases as needed for other forms.		}		handled = true;	}	return handled;}/*********************************************************************** * FUNCTION:    	AppEventLoop * * DESCRIPTION: 	The main event loop for the application.   * * RETURNED:    	nothing ***********************************************************************/ static void AppEventLoop(	void){	UInt16 		error;	EventType 	event;	do {		EvtGetEvent ( &event, evtWaitForever );				if ( event.eType == keyDownEvent &&			event.data.keyDown.chr == vchrHardAntenna ) continue;				if (! SysHandleEvent ( &event))			if (! MenuHandleEvent ( 0, &event, &error ))				if (! AppHandleEvent ( &event ))					FrmDispatchEvent ( &event );	} while ( event.eType != appStopEvent );}/*********************************************************************** * FUNCTION:     	AppStart * * DESCRIPTION:  	Do whatever is necessary to get started, like read the app preferences. * * RETURNED:     	Err value or 0 if nothing went wrong ***********************************************************************/ static UInt32 AppStart(	void){// Return an error code if necessary. 	return 0;}/*********************************************************************** * FUNCTION:    	AppStop * * DESCRIPTION: 	Do whatever you need to do, like save the preferences. * * RETURNED:    	nothing ***********************************************************************/static void AppStop(	void){	FrmCloseAllForms ();}/*********************************************************************** * FUNCTION:    PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED:    0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/ UInt32 PilotMain(	UInt16	cmd,					// The launch code	MemPtr	/* cmdPBP*/,		// Pointer to the launch code structure	UInt16	launchFlags			// Extra launch info){	UInt32 error = 0;	UInt32 value;// Check the ROM version for compatibility.	error = RomVersionCompatible ( MIN_ROM_VERSION, launchFlags);	if ( error == 0 )	{// Does it have the INetLib?// ROM OK, check for the various launch codes as needed.				switch (cmd)		{			case sysAppLaunchCmdNormalLaunch:							error = FtrGet(inetLibFtrCreator,					inetFtrNumVersion, &value);							if ( error == 0 )				{					error = AppStart ();// Patch for antenna problems ONLY ON EMULATOR					if ( HostGetHostID() == hostIDPalmOSEmulator )						PatchKCS();					if ( error == 0 )					{						FrmGotoForm ( MainForm );						AppEventLoop ();						AppStop ();					}					if ( HostGetHostID() == hostIDPalmOSEmulator )						RemovePatchKCS();					break;				}								else				{					FrmAlert( NoInetLibAlert );				}										}	}	return error;}/*********************************************************************** * FUNCTION:    	TestWithRandom * * DESCRIPTION: 	Tests the GUI with random values. Not called. * * RETURNED:    	nothing ***********************************************************************/void TestWithRandom( void ){	static char temperatureStr[ 64 ];	static char windStr[ 64 ];	// Generate a random gWxData.temperature & wind	gWxData.temperature = (Int16)( ( (float)SysRandom ( 0 ) / (float)sysRandomMax ) * 100.0 + 20.0 );	gWxData.windDir = (UInt16)( ( (float) SysRandom ( 0 ) /(float) sysRandomMax * 360.0 ) );		StrPrintF ( temperatureStr, "%d \260F     ", gWxData.temperature );	StrPrintF ( windStr, "0 mph from %d \260     ", gWxData.windDir );	CtlSetLabel ( GetObjectPtr ( MainTempLabel ), temperatureStr );	CtlSetLabel ( GetObjectPtr ( MainWindLabel ), windStr );			// Force an update	FrmUpdateForm( MainForm, frmRedrawUpdateCode );}typedef UInt32 (_kcsFuncPtr)( void );typedef _kcsFuncPtr kcsFuncPtr;kcsFuncPtr *x;/*********************************************************************** * FUNCTION:    	KeyCurrentStatePatch * * DESCRIPTION: 	Returns which keys are down; fools caller into thinking * antenna is up. * * RETURNED:    	nothing ***********************************************************************/UInt32 KeyCurrentStatePatch(	void){	UInt32 result = (*x)();// Trust me, the antenna is UP!	result |= keyBitAntenna;	return result;}/*********************************************************************** * FUNCTION:    	PatchKCS * * DESCRIPTION: 	Installs KeyCurrentStatePatch as active KeyCurrentState * Trap handler. * * RETURNED:    	nothing ***********************************************************************/void PatchKCS(	void){// Get the address of the KeyCurrentState function.	x = SysGetTrapAddress ( sysTrapKeyCurrentState );// Install our patch	SysSetTrapAddress ( sysTrapKeyCurrentState, KeyCurrentStatePatch );}/*********************************************************************** * FUNCTION:    	RemovePatchKCS * * DESCRIPTION: 	Installs system KeyCurrentState code as active KeyCurrentState * Trap handler. * * RETURNED:    	nothing ***********************************************************************/void RemovePatchKCS(	void){		SysSetTrapAddress ( sysTrapKeyCurrentState, x );}

⌨️ 快捷键说明

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