From: chuck@gte.com (Chuck Hoffman)
Newsgroups: comp.sys.mac.programmer
Subject: Re: CountAppFiles --- and starting a child process
Date: 8 Oct 92 13:07:46 GMT
Followup-To: comp.sys.mac.programmer
Organization: GTE Laboratories

In article <1992Oct07.000624.14905@wes.on.ca>, tomh@wes.on.ca (Tom
Haapanen) wrote:
> 
> My Mac app is progressing (thanks to those who helped me out at an earlier
> stage), and my collection of Inside Mac volumes is growing.  :)  However,
> I have run into some more roadblocks.
> 
>   - I'm using CountAppFiles as described in both Inside Mac and Macintosh
>     Revealed.  However, no matter how many files I drag to my app, or how
>     many data files I try to print, the second parameter gets set to 0.  The
>     app starts up fine from double-clicking on a datafile, but there is no
>     filename that I could open.
> 
>     My Think C 5.0 code fragment:
> 
> 	  short iWhat, iCount;
> 	  CountAppFiles( &iWhat, &iCount );

Tom,
   The following routine is from a sample application I wrote.  THINK C
release 5.0 - 5.0.3.  It works fine.  The only difference I see is that I
defined the count as an int, instead of short.  I'm making a bug fix to the
app, called "Chassis" this weekend.  If you want a copy, please send me a
mailing address ("real" mail, not e-mail) and I'll send it to you for the
low, low "price" of asking you to beta test the bug fix.  I'll put it out
on the net after it has been tested.
   Sorry, can't help with your other question about spawning or attaching
other processes.  I doubt that the Mac OS can truly do that, but there may
be some fakey way.

Chuck Hoffman
chuck@gte.com
GTE Laboratories, Waltham, Massachusetts, USA
(617) 466-2131
=====================================
I'm not sure why we're here, but I am sure that while we're here we're
supposed to help each other.
=====================================
/************************************************************************************/
/*	FinderFilesProc																	*/
/*																					*/
/*	If the program was entered by the user's selecting one or more files,
and then	*/
/*	using "Open" from the Finder menu (or command-O, or by dragging the file
icons	*/
/*	into the application program icon (System 7)), open each of the
files.			*/
/*																					*/
/*	If the program was entered by the user's selecting one or more files,
and then	*/
/*	using "Print" from the Finder menu (or command-P), then for each file,
open it,	*/
/*	print it, and close it.  After this has been done for each file,
quit.			*/
/************************************************************************************/

#include "MyHeaders.h"

int FinderFilesProc ()
{
	int		FFRetCode = 0;

	UseResFile (initResRefNum);						/* for H/P printer				*/
		
	appIndex = 1;									/* initialize					*/
	CountAppFiles (&appMessage, &appCount);			/* How many from Finder?		*/
	if (appCount > 0)								/* if 1 or more					*/
		{
		if (appMessage == appOpen)					/* if they are for "Open"		*/
			{
			for (appIndex=1; appIndex <= appCount; appIndex++)	/* for each one		*/
				{
				appMenuLong = ((0x010000 * FileMenuID) + OpenItem);	/* menu parm	*/
				WorkRetCode = MenuProc (appMenuLong);	/* do "open" menu item		*/
				if (WorkRetCode != 0)
					break;
				ClrAppFiles (appIndex);					/* remove from Finder list	*/
				}
			}
		else
		if (appMessage == appPrint)					/* if they are for "Print"		*/
			{
			for (appIndex=1; appIndex <= appCount; appIndex++)	/* for each one		*/
				{
				appMenuLong = ((0x010000 * FileMenuID) + OpenItem);	/* menu parm	*/
				WorkRetCode = MenuProc (appMenuLong);	/* do "open" menu item		*/
				if (WorkRetCode != 0)
					break;

				appMenuLong = ((0x010000 * FileMenuID) + PrintItem); /* menu parm	*/
				WorkRetCode = MenuProc (appMenuLong);	/* do "print" menu item		*/
				if (WorkRetCode != 0)
					break;

				appMenuLong = ((0x010000 * FileMenuID) + CloseItem); /* menu parm	*/
				WorkRetCode = MenuProc (appMenuLong);	/* do "close" menu item		*/

				ClrAppFiles (appIndex);					/* remove from Finder list	*/
				}

			appMenuLong = ((0x010000 * FileMenuID) + QuitItem);		/* menu parm	*/
			WorkRetCode = MenuProc (appMenuLong);		/* do "quit" menu item		*/
			}
		}

	return FFRetCode;
}
Newsgroups: comp.sys.mac.programmer