Print Documents Event
Print Documents Event
To handle the Print Documents event, your application should print the
documents specified in the Apple event. The Print Documents event
contains a list of documents to print in its direct parameter. Your application
extracts this information and then prints the specified documents. Your
application should not open any windows for the documents. Also note that your
application should remain open after processing the
Print Documents event; when appropriate, the Finder sends your
application a Quit Application event immediately after sending it a
Print Documents event.
The following program shows a handler for the Print Documents event.
This handler is similar to the handler for the Open Documents event. The code
illustrates how to print the documents referred to in the direct parameter.
// A handler for the Print Documents event
// Assuming inclusion of
#include <AppleEvents.h>
pascal OSErr MyHandlePDOC (AppleEvent * theAppleEvent,
AppleEvent * reply,
long handlerRefcon);
OSErr MyGotRequiredParams (AppleEvent * theAppleEvent);
void DoError (OSErr myErr);
OSErr MyPrintFile (FSSpec * myFSS);
pascal OSErr MyHandlePDOC (AppleEvent * theAppleEvent,
AppleEvent * reply,
long handlerRefcon)
{
FSSpec myFSS;
AEDescList docList;
OSErr myErr;
long index, itemsInList;
Size actualSize;
DescType returnedType;
// get the direct parameter--a descriptor list--and put
// it into docList
myErr = AEGetParamDesc( theAppleEvent, keyDirectObject,
typeAEList, & docList);
if ( myErr)
DoError( myErr);
// check for missing required parameters
myErr = MyGotRequiredParams( theAppleEvent);
if ( myErr) {
// an error occurred: do the necessary error handling
myErr = AEDisposeDesc(& docList);
return myErr;
}
// count the number of descriptor records in the list
myErr = AECountItems (& docList,& itemsInList);
// now get each descriptor record from the list, coerce
// the returned data to an FSSpec record, and print the
// associated file
for ( index=1; index<= itemsInList; index++) {
myErr = AEGetNthPtr(& docList, index, typeFSS, &keywd,
& returnedType, (Ptr)& myFSS,
sizeof( myFSS), & actualSize);
if ( myErr)
DoError( myErr);
myErr = MyPrintFile(& myFSS);
if ( myErr)
DoError( myErr);
}
myErr = AEDisposeDesc(& docList);
return noErr;
}
A listing of MyGotRequiredParams may be found under
Writing Apple Event Handlers.