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

📄 gmdbview.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************* FILE:					GMDBView.c** DESCRIPTION:	A generic database viewer for the Global Messaging Project.** VERSION:			4.0**********************************************************************/#include <PalmOS.h>#include "GMDBView.h"#include "GMDBViewRsc.h"#include "Utils.h"#include "UtilsRsc.h"/*********************************************************************** * FUNCTION:    	DisplayDialogMsg * * DESCRIPTION: 	Display a message on the progress dialog * * RETURNED:    	nothing ***********************************************************************/static void DisplayDialogMsg(	Char *		msg		// ( in ) message to display on the progress dialog){	WinDrawChars ( msg, StrLen ( msg ),  DIALOG_MSG_X, DIALOG_MSG_Y );}/*********************************************************************** * FUNCTION:    	TimeToDrawIcon * * DESCRIPTION: 	Checks to see if it's time to draw another animated icon. *							It's time if gTicksPerIcon ticks have passed since the last drawing. * * RETURNED:    	true if it's time to draw another icon ***********************************************************************/static Boolean 	TimeToDrawIcon	// ( out ) time to draw?(	void){	Boolean			update = false;	UInt32				nowTicks = TimGetTicks ();// Check to see if gTicksPerIcon have passed		if ( nowTicks - gThenTicks > gTicksPerIcon )	{	// Yes, reset the ticks count for the next calculation and		update 			= true;		gThenTicks 	= nowTicks;	}	return ( update );}/*********************************************************************** * FUNCTION:    	RotateDialogIcon * * DESCRIPTION: 	Draw the next phase of an animated icon if it's time. * * RETURNED:    	Nothing ***********************************************************************/static void 		RotateDialogIcon(	Int16			direction	// ( in )  1 = forwards, -1 = backwards){	UInt16			iconIDs [ NUM_ICONS ] = 							{ Glass1Bitmap, Glass2Bitmap, Glass3Bitmap, Glass4Bitmap };	static Int16	iconCnt;	MemHandle	resH;		if ( TimeToDrawIcon ())	{	// Adjust the icon # and correct for boundaries		iconCnt = iconCnt + direction;		if ( iconCnt > NUM_ICONS - 1 )		{			iconCnt = 0;		}		if ( iconCnt < 0 )		{			iconCnt = NUM_ICONS - 1;		}// Get the proper icon for display			resH = DmGetResource ( bitmapRsc, iconIDs [ iconCnt ] );		if ( resH )		{			BitmapPtr		resP = MemHandleLock ( resH );			if ( resP )			{			// Display the icon				WinDrawBitmap ( resP, DIALOG_PIC_X, DIALOG_PIC_Y );				MemPtrUnlock ( resP );			}			DmReleaseResource ( resH );		}	}}/*********************************************************************** * FUNCTION:    	DialogCanceled * * DESCRIPTION: 	Handle events for the progress dialog. * * RETURNED:    	true if canceled ***********************************************************************/static Boolean DialogCanceled	// ( out )  User canceled?(	void){	EventType 		event;	Boolean			canceled = false;	ControlPtr		ctlP = ( ControlPtr ) GetObjectPtr ( ScanningCancelButton );	// Check for low and high-level events.	if ( EvtSysEventAvail ( false )  || EvtEventAvail ( )) 	{		EvtGetEvent ( &event, 0);		// If the cancel button has been clicked, let the caller know.		if ( event.eType == ctlSelectEvent  && 			event.data.ctlSelect.controlID == ctlP->id )		{			WinInvertRectangle ( &ctlP->bounds, 4 );			canceled = true;		}		 // Nope, let the system or the control event manager deal with it.		if ( !SysHandleEvent ( &event ))		{			CtlHandleEvent ( ctlP, &event );		}	}	return ( canceled);}#pragma mark ----------------/*********************************************************************** * FUNCTION:    	FoundHeaderInRec * * DESCRIPTION: 	Scan thru a database record looking for a specific string. * * RETURNED:    	A pointer to the start of the string within the record or -1 ***********************************************************************/static Int16 	FoundHeaderInRec	//  ( out ) pointer to record byte(	Char *			recP,		// ( in )  pointer to record to scan	Int16			recLen	// ( in )  record length){	Int16			result = -1, curCharP = 0, matchCnt = 0;	// Loop thru the record's bytes looking for a match		while (( curCharP < recLen) && ( matchCnt < MSG_HEADER_LEN ))	{			if ( recP [ curCharP++ ] == MSG_HEADER [ matchCnt ] )		// The current character matches, continue		{			matchCnt++;		}		else		// No match on current character, reset message pointer		{			matchCnt = 0;		}	}	// Check to see if we found a full-string match.// If so, prep the return value.	if ( matchCnt == MSG_HEADER_LEN )		result = curCharP - matchCnt;			return ( result );}/*********************************************************************** * FUNCTION:    	ScanThruRecords * * DESCRIPTION: 	Scan through the virtual database # dbIndex looking for *							our "unique" record header string. * * RETURNED:    	true if operation cancelled ***********************************************************************/static Boolean ScanThruRecords	// ( out )  operation canceled?(	UInt16				cardNum,		// ( in )  the database card #	LocalID			dbID				// ( in )  the database LocalID){	DmOpenRef	dbRef;	UInt16				recCnt, curRec = 0, j = 0;	MemHandle	recH;	Char*				recP;	Int16				hdrOffset, recLen;	Boolean			canceled = false;// Open the database			dbRef = DmOpenDatabase ( cardNum, dbID, dmModeReadOnly+dmModeShowSecret );	if ( dbRef )	{		recCnt = DmNumRecordsInCategory ( dbRef, dmAllCategories );	// search through database records looking for our header.// We find all headers in a database, but only the first in a record.		while ( curRec < recCnt && ! canceled )		{		// Update the progress dialog icon				RotateDialogIcon ( FORWARDS);			// Get the next record			recH = DmQueryNextInCategory ( dbRef, &curRec, dmAllCategories );			if ( recH ) {				recP = MemHandleLock ( recH );				if ( recP ) {// Look for message header in the record					recLen 		= ( Int16 ) MemPtrSize ( recP );					hdrOffset 	= FoundHeaderInRec ( recP, recLen );					if ( hdrOffset >= 0 )					{					// Header found, do something useful with the data						for ( j = 0; j < 100; j++ )	// For testing purposes only						{							DisplayDialogMsg ( DIALOG_UPDATE_MSG );							RotateDialogIcon ( BACKWARDS);							if ( DialogCanceled ())							{								canceled = true;								break;							}						}						// Done working, redisplay the scanning message						DisplayDialogMsg ( DIALOG_SCAN_MSG );					}				}				// Release/close relevant resources				MemHandleUnlock ( recH );				curRec++;		}	}		DmCloseDatabase ( dbRef );	}	else		FrmAlert ( CantGetDatabaseInfoAlert );			return ( canceled );}/*********************************************************************** * FUNCTION:    	DBShouldBeScanned * * DESCRIPTION: 	Check to see if the records in a database should be *							scanned for our content header. DBs are excluded *							on the basis of various type/creator combinations. * * RETURNED:    	the DB's local ID if should be scanned ***********************************************************************/ static 	LocalID 	DBShouldBeScanned 	// ( out )  should be scanned?(	UInt16			cardNum,		// ( in )  database card #	UInt16			dbIndex			// ( in )  database index on that card){	UInt16			attributes;	LocalID		dbID = 0;	Err				error;	union	{		UInt32		type;		Char		letters [ 4 ];	} typeInfo;// Get the database LocalID			dbID = DmGetDatabase ( cardNum, dbIndex );	if ( dbID )	{	// Get the database type and creator		error = DmDatabaseInfo (			cardNum, dbID, NULL, &attributes, 			NULL, NULL, NULL,  NULL,  NULL, NULL,  NULL, 			&typeInfo.type, NULL );		if ( ! error )		{		// Eliminate hidden, resource, and launchable databases			if ( attributes & ( dmHdrAttrResDB | dmHdrAttrHidden | dmHdrAttrLaunchableData ))			{				dbID = 0;			}			// Elminate any type that is all lowercase letters (OS types)			else			if ( TxtCharIsLower ( typeInfo.letters [ 0 ] )  &&				TxtCharIsLower ( typeInfo.letters [ 1 ] ) &&				TxtCharIsLower ( typeInfo.letters [ 2 ] ) &&				TxtCharIsLower ( typeInfo.letters [ 3 ] ))			{				dbID = 0;			}		}			// If there's a DmDatabaseInfo error, skip this database		else dbID = 0;	}	return ( dbID );}/*********************************************************************** * FUNCTION:    	ScanThruDatabases * * DESCRIPTION: 	Scan throught the databases. * * RETURNED:    	nothing ***********************************************************************/static void ScanThruDatabases(	void){	Int16				dbNum = 0;	FormPtr			frmP, saveFrmP;	UInt16				cardNum, dbIndex;	LocalID			dbID = 0;	Boolean			canceled = false;	// Display the progress dialog		saveFrmP 	= FrmGetActiveForm ( );	frmP 			= FrmInitForm ( ScanningForm);	FrmDrawForm ( frmP );	FrmSetActiveForm ( frmP );		// Scan through the databases, refreshing the icon when needed	DisplayDialogMsg ( DIALOG_SCAN_MSG );	do	{		// Display the scanning message and icon		RotateDialogIcon ( FORWARDS );						// Scan the database contents if it's of interest.		GetRealDBIndex ( dbNum++, &cardNum, &dbIndex );		dbID = DBShouldBeScanned ( cardNum, dbIndex );		if ( dbID > 0 )		{			canceled = ScanThruRecords ( cardNum, dbID );		}	} while ( ! canceled && ! DialogCanceled () && dbNum < gTotDBsNum );	// Done, remove the progress dialog and restore the main form	FrmEraseForm ( frmP );	FrmDeleteForm ( frmP );	FrmSetActiveForm ( saveFrmP );}#pragma mark ----------------/*********************************************************************** * FUNCTION:    	GetRealDBIndex * * DESCRIPTION: 	Convert the virtual DB Index into a Card/Index pair. * * RETURNED:    	stores card # and DB index in passed addresses ***********************************************************************/static void GetRealDBIndex(	Int16		virIndex,	// ( in )  the virtual database number	UInt16*	cardNum,	// ( out ) the actual card number	UInt16*	dbIndex		// ( out) the actual database number)		{	UInt16		start = 0, end = 0, i = 0;// Scan thru the database counts to find the card and DB index// that the current virtual database index fits into.		do	{	// Get card db# boundaries		end 	= end 	+ gDBCounts [ i ];		if ( virIndex >= start && virIndex < end )		// Current db# fits in boundaries, return values and exit		{			* cardNum	= i;			* dbIndex 	= virIndex - start;			break;		}// Not yet found, move to next card		else			start = start + gDBCounts [ i++ ];	}	while (( gDBCounts [ i ] > 0 ) && ( i < MAX_NUM_CARDS ));}/*********************************************************************** * FUNCTION:    	MoveForwardInDatabases * * DESCRIPTION: 	Names kinda says it all. * * RETURNED:    	nothing. Sets gVirDBIndex ***********************************************************************/static void MoveForwardInDatabases(	UInt8		increment		// ( in )  the # of databases to move forward)		{// Check to see if at end of the database list	if ( gVirDBIndex >= gTotDBsNum - 1 )	{		SndPlaySystemSound ( sndWarning );	}

⌨️ 快捷键说明

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