[comp.sys.mac.programmer] Using Process Manager and SetDepth

tagreen@lothario.ucs.indiana.edu (Todd Green) (06/12/91)

I've come to notice that my 38.4K modem can deliver data faster than
White Knight can display it in 8-bit color, so I'm writing a little
background application that checks to see if WK is the foreground app,
and if so sets the depth to 4-bit color, otherwise it returns the
monitor to it's previous state.  Everything is hunky-dorey execpt for
the fact that SetDepth() fails to redraw the menubar correctly.  The
menubar remains functional, but when the depth is changed it looks
like the menu bar is drawn with a xOr (black and white pattern). Could
someone please look at the code below and tell me what's wrong. I've
tried to only include what's necessary, and I apologize for the ugly
way that the text transfered.  Pretty ugly in 80 columns, but should
expand fine to 132.  Also on a side note, which managers should you
NOT initialize for a background only app?  Currently I'm doing them
all expect for InitWindows() as stated in IM VI.

Again thanks in advance for the words of wisdom.

Todd
P.S. OH, THINK C 4.0.5 with sys7 libs and  headers.
------
typedef struct	envInfo {
	Boolean		isMono, oldIsMono,
			contextSwitch;
	int		pixelDepth, oldPixelDepth;
	GDHandle	gDevice;
} EnvInfo, *EnvInfoPtr, **EnvInfoHandle;

OSErr CheckDepth( EnvInfoPtr theEnv )
{
	ProcessInfoRec		procInfo;
	ProcessSerialNumber	psn, frontPSN;
	Boolean			isSameProcess;
	OSErr			theError;
			
	psn.highLongOfPSN = 0;
	psn.lowLongOfPSN  = kNoProcess;
	procInfo.processInfoLength = sizeof( ProcessInfoRec );
	procInfo.processName = (StringPtr)NewPtr( 32 );
	procInfo.processAppSpec = kNilPointer;

	while( (GetNextProcess( &psn )) == noErr ) {		
		if( (theError = GetProcessInformation( &psn, &procInfo )) != noErr ) {
			SysBeep(1);
			ExitToShell();
		} else {
			if( (procInfo.processSignature == (long)'WK11') && (procInfo.processType == 'APPL') ) {
				if( (GetFrontProcess( &frontPSN )) != noErr ) {
					SysBeep(1);
					ExitToShell();
				} else {
					if( (SameProcess( &psn, &frontPSN, &isSameProcess )) != noErr ) {
						SysBeep(1);
						ExitToShell();
					} else {
						if( isSameProcess ) {
							if( theEnv->pixelDepth != 4 ) {
								SetDepth( theEnv->gDevice, 4, gdDevType, kMono );
								theEnv->oldPixelDepth = theEnv->pixelDepth;
								theEnv->oldIsMono = theEnv->isMono;
								theEnv->contextSwitch = TRUE;
							}
						} else {
							if( theEnv->contextSwitch ) {
								if( theEnv->oldPixelDepth != theEnv->pixelDepth ) {
									SetDepth( theEnv->gDevice, theEnv->oldPixelDepth, gdDevType, theEnv->oldIsMono );
									theEnv->contextSwitch = FALSE;
								}
							}
						}
					}
				}
			}
		}
	}
	return( noErr );
}
-- 
Internet: tagreen@bronze.ucs.indiana.edu
NeXTMail: tagreen@lothario.ucs.indiana.edu
BitNet:   tagreen@iubacs.bitnet