Contribute  :  Calendar  :  Advanced Search  :  Site Statistics  :  Directory  :  Files to download  :  Links for developers  :  Privacy policy  :  Web Resources  :  Polls  
    MacOSX Guru Site Information, tips and tricks, FAQ for Mac OS X developers    
 Welcome to MacOSX Guru Site
 Tuesday, October 23 2018 @ 12:19 AM BST

How do I find out about files dropped on my app's icon?

Carbon Development FAQWant to know how to detect when a user wants to open a file with your application, by double-clicking it in the Finder, or by dragging and dropping it on your application's Finder or dock icon? The solution is the "open document" Apple Event.

Whenever the Finder needs to notify your application of a user request for opening a document with your application, it sends you an { kCoreEventClass, kAEOpenDocuments } Apple Event. This Apple Event contains a list of files to open as its direct argument. To unpack them, use code like:

	FSRef				vFile;
	AEDescList			docList;
	long				x, numDocs;
	AEKeyword			vKeyword;
	DescType			vOutType;
	Size				vOutActualSize;
	OSErr				vErr;
	// Get list of files from Apple Event and count its items:
	vErr = AEGetParamDesc( sEvent, keyDirectObject, typeAEList, &docList );	
	vErr = AECountItems( &docList, &numDocs );
	// Go through list and open all  items:
	for( x = 1; x <= numDocs; x++ )
		// Get an FSSpec to our file:
		vErr = AEGetNthPtr( &docList,
				&vOutActualSize );
		MyOpenOneFile( &vFile );
	vErr = AEDisposeDesc( &docList );
Other useful Apple Events include the "open application" event, which is sent instead of an "open documents" event whenever your application is launched directly, without any documents, and the "reopen applications" event, which is sent whenever the user directly opens your application (which includes clicking its dock icon) while it is already running.

What's Related

Story Options

How do I find out about files dropped on my app's icon? | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
 Copyright © 2018 MacOSX Guru Site
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.07 seconds