const StringPtr kApplicationName = "\pYourAppNameHere"; ////////// // // GetOneFileWithPreview // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user // selects a file, return information about it using the theFSSpecPtr parameter. // // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file // filter function to return true if a file is to be displayed, while the Standard File Package expects the // filter to return false if a file is to be displayed. // ////////// OSErr GetOneFileWithPreview (short theNumTypes, TypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc) { #if TARGET_OS_WIN32 StandardFileReply myReply; #endif #if TARGET_OS_MAC NavReplyRecord myReply; NavDialogOptions myDialogOptions; NavTypeListHandle myOpenList = NULL; NavEventUPP myEventUPP = NewNavEventUPP(HandleNavEvent); #endif OSErr myErr = noErr; if (theFSSpecPtr == NULL) return(paramErr); #if TARGET_OS_WIN32 // prompt the user for a file StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply); if (!myReply.sfGood) return(userCanceledErr); // make an FSSpec record myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr); #endif #if TARGET_OS_MAC // specify the options for the dialog box NavGetDefaultDialogOptions(&myDialogOptions); myDialogOptions.dialogOptionFlags -= kNavNoTypePopup; myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles; BlockMoveData(kApplicationName, myDialogOptions.clientName, kApplicationName[0] + 1); // create a handle to an 'open' resource myOpenList = (NavTypeListHandle)CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList); if (myOpenList != NULL) HLock((Handle)myOpenList); // prompt the user for a file myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL); if ((myErr == noErr) && myReply.validRecord) { AEKeyword myKeyword; DescType myActualType; Size myActualSize = 0; // get the FSSpec for the selected file if (theFSSpecPtr != NULL) myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize); NavDisposeReply(&myReply); } if (myOpenList != NULL) { HUnlock((Handle)myOpenList); DisposeHandle((Handle)myOpenList); } DisposeNavEventUPP(myEventUPP); #endif return(myErr); }
////////// // // GetOneFileWithPreview // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user // selects a file, return information about it using the theFSSpecPtr parameter. // // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file // filter function to return true if a file is to be displayed, while the Standard File Package expects the // filter to return false if a file is to be displayed. // ////////// OSErr GetOneFileWithPreview(short theNumTypes, TypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc) { #if TARGET_OS_WIN32 StandardFileReply myReply; #endif #if TARGET_OS_MAC NavReplyRecord myReply; NavDialogOptions myDialogOptions; NavTypeListHandle myOpenList = NULL; NavEventUPP myEventUPP = NewNavEventUPP(HandleNavEvent); #endif OSErr myErr = noErr; if (theFSSpecPtr == NULL) return(paramErr); #if TARGET_OS_WIN32 // prompt the user for a file StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply); if (!myReply.sfGood) return(userCanceledErr); // make an FSSpec record myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr); #endif #if TARGET_OS_MAC // specify the options for the dialog box NavGetDefaultDialogOptions(&myDialogOptions); myDialogOptions.dialogOptionFlags -= kNavNoTypePopup; myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles; BlockMoveData(kApplicationName, myDialogOptions.clientName, kApplicationName[0] + 1); // create a handle to an 'open' resource myOpenList = (NavTypeListHandle)CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList); if (myOpenList != NULL) HLock((Handle)myOpenList); // prompt the user for a file myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL); if ((myErr == noErr) && myReply.validRecord) { AEKeyword myKeyword; DescType myActualType; Size myActualSize = 0; // get the FSSpec for the selected file if (theFSSpecPtr != NULL) myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize); NavDisposeReply(&myReply); } if (myOpenList != NULL) { HUnlock((Handle)myOpenList); DisposeHandle((Handle)myOpenList); } DisposeNavEventUPP(myEventUPP); #endif return(myErr); }