File Dialog Utilities
File Dialog Utilities
/*File dialog utilities
* File dialog functions for use with C file i/o
* ChooseFileDialog() and ChooseNewFileDialog()
/* ChooseFileDialog and ChooseNewFileDialog each return an error code of 1
* if the user hits cancel. Otherwise they set the default volume to the
* volume of the file and return the filename in filename. This filename
* can then be used in any C file i/o calls.
* NOTE: You must pass a string to these routines that is large enough to
* hold the filename (this is 31 characters + a null character maximum) */
/* IMPORTANT: If you intend to build standalone applications, you MUST
* call the standard stream once or initialize the Mac toolbox before
* calling these functions (see sample main() below) */
// Assumes inclusion of
#include
#include < string.h>
#include < pascal.h>
#include
short ChooseFileDialog (char *fileName);
short ChooseNewFileDialog (char *newFileName);
short ChooseFileDialog (char *fileName)
{
SFReply reply;
static Point where;
SFTypeList typeList;
SFGetFile ( where, "\p", nil, -1, typeList, nil, &reply );
if (reply.good) {
SetVol (nil, reply.vRefNum);
strcpy (fileName, PtoCstr (reply.fName));
return noErr;
}
else
return 1;
}
short ChooseNewFileDialog (char *fileName)
{
SFReply reply;
static Point where;
SFTypeList typeList;
SFPutFile ( where, "\p", "\p", nil, &reply );
if (reply.good) {
SetVol (nil, reply.vRefNum);
strcpy (fileName, PtoCstr (reply.fName));
return noErr;
}
else
return 1;
}
/*Here is a very short test program which demonstrates
* how these functions should be called
*/
#include
#define MaxFileNameLen 32
main ()
{
char fileName[MaxFileNameLen], newFileName[MaxFileNameLen];
short err;
cshow(stdout); /* call standard stream to initialize the mac toolbox*/
err = ChooseFileDialog (fileName);
if (!err)
printf ("%s\n", fileName);
err = ChooseNewFileDialog (newFileName);
if (!err)
printf ("%s\n", newFileName);
}