Important: The information in this document is obsolete and should not be used for new development.
Setting the Current Directory
The first time your application calls one of the Standard File Package routines, the default current directory (that is, the directory whose contents are listed in the dialog box) is determined by the way in which your application was launched.
At each subsequent call to one of the Standard File Package routines, the default current directory is simply the directory that was current when the user completed the previous dialog box. You can use the function
- If the user launched your application directly (perhaps by double-clicking its icon in the Finder), the default directory is the directory in which your application is located.
- If the user launched your application indirectly (perhaps by double-clicking one of your application's document icons), the default directory is the directory in which that document is located.
GetSFCurDir
defined in Listing 3-11 to determine the current directory.Listing 3-11 Determining the current directory
FUNCTION GetSFCurDir: LongInt; TYPE LongIntPtr = ^LongInt; CONST CurDirStore = $398; BEGIN GetSFCurDir := LongIntPtr(CurDirStore)^; END;You can use theGetSFCurVol
function defined in Listing 3-12 to determine the
current volume.Listing 3-12 Determining the current volume
FUNCTION GetSFCurVol: Integer; TYPE IntPtr = ^Integer; CONST SFSaveDisk = $214; BEGIN GetSFCurVol := -IntPtr(SFSaveDisk)^; END;If necessary, you can change the default current directory and volume. For example,
when the user needs to select a dictionary file for a spell-checking application, the application might set the current directory to a directory containing document-specific dictionary files. This saves the user from having to navigate the directory hierarchy from the directory containing documents to that containing dictionary files. You can use the procedureSetSFCurDir
defined in Listing 3-13 to set the current directory.Listing 3-13 Setting the current directory
PROCEDURE SetSFCurDir (dirID: LongInt); TYPE LongIntPtr = ^LongInt; CONST CurDirStore = $398; BEGIN LongIntPtr(CurDirStore)^ := dirID; END;You can use the procedureSetSFCurVol
defined in Listing 3-14 to set the current volume.Listing 3-14 Setting the current volume
PROCEDURE SetSFCurVol (vRefNum: Integer); TYPE IntPtr = ^Integer; CONST SFSaveDisk = $214; BEGIN IntPtr(SFSaveDisk)^ := -vRefNum; END;If you are using the enhanced Standard File Package routines, you can set the current directory by filling in the fields of the file system specification in the reply record passed to
- Note
- Most applications don't need to alter the default current directory
or volume.CustomGetFile
orCustomPutFile
. You do this within your dialog hook function. Listing 3-15 defines a dialog hook function that makes the currently active System Folder the current directory.Listing 3-15 Setting the current directory
FUNCTION MyDlgHook (item: Integer; theDialog: DialogPtr; myDataPtr: Ptr): Integer; VAR myReplyPtr: StandardFileReplyPtr; foundVRefNum: Integer; foundDirID: LongInt; myErr: OSErr; BEGIN MyDlgHook := item; {by default, return the item passed in} IF GetWRefCon(WindowPtr(theDialog)) <> LongInt(sfMainDialogRefCon) THEN Exit(MyDlgHook); {this function is only for main dialog box} CASE item OF sfHookFirstCall: {pseudo-item: first time function called} BEGIN myReplyPtr := StandardFileReplyPtr(myDataPtr); myErr := FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, foundVRefNum, foundDirID); IF myErr = noErr THEN BEGIN myReplyPtr^.sfFile.parID := foundDirID; myReplyPtr^.sfFile.vRefNum := foundVRefNum; MyDlgHook := sfHookChangeSelection; END; END; OTHERWISE ; {ignore all other items} END; END;This dialog hook function installs the System Folder's volume reference number and parent directory ID into the file system specification whose address is passed in themyDataPtr
parameter. Because the dialog hook function returns the constantsfHookChangeSelection
the first time it is called (that is, in response to thesfHookFirstCall
pseudo-item), the Standard File Package sets the current directory to the indicated directory when the dialog box is displayed.