Creates a Save dialog box that lets the user specify the drive, directory, and name of a file to save.
GetSaveFileName([nFlags [, cFileFilters [, cFileName [, cInitialDirectory [, cDialogTitle [, nFlagsEx [, cCallbackFunc]]]]]]])
Parameters
- nFlags (optional, additive)
If you omit nFlags parameter or pass 0 these flags are used:
OFN_EXPLORER | OFN_NOCHANGEDIR
Valid flags:Flag Meaning OFN_CREATEPROMPT If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. OFN_DONTADDTORECENT Windows 2000/XP: Prevents the system from adding a link to the selected file in the file system directory that contains the user's most recently used documents. OFN_EXPLORER If you want the old-style user interface, omit the OFN_EXPLORER flag. OFN_FILEMUSTEXIST Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used. This flag can be used in an Open dialog box. It cannot be used with a Save As dialog box. OFN_FORCESHOWHIDDEN Windows 2000/XP: Forces the showing of system and hidden files, thus overriding the user setting to show or not show hidden files. However, a file that is marked both system and hidden is not shown. OFN_LONGNAMES For old-style dialog boxes, this flag causes the dialog box to use long file names. If this flag is not specified, or if the OFN_ALLOWMULTISELECT flag is also set, old-style dialog boxes use short file names (8.3 format) for file names with spaces. Explorer-style dialog boxes ignore this flag and always display long file names. OFN_NOCHANGEDIR Restores the current directory to its original value if the user changed the directory while searching for files. OFN_NODEREFERENCELINKS Directs the dialog box to return the path and file name of the selected shortcut (.LNK) file. If this value is not specified, the dialog box returns the path and file name of the file referenced by the shortcut. OFN_NOLONGNAMES For old-style dialog boxes, this flag causes the dialog box to use short file names (8.3 format). Explorer-style dialog boxes ignore this flag and always display long file names. OFN_NONETWORKBUTTON Hides and disables the Network button. OFN_NOREADONLYRETURN Specifies that the returned file does not have the Read Only check box selected and is not in a write-protected directory. OFN_NOTESTFILECREATE Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network share. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or network protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed. OFN_OVERWRITEPROMPT Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file. OFN_PATHMUSTEXIST Specifies that the user can type only valid paths and file names. If this flag is used and the user types an invalid path and file name in the File Name entry field, the dialog box function displays a warning in a message box. OFN_READONLY Causes the Read Only check box to be selected initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed.
- cFileFilters (optional)
default = 'All' + CHR(0) + '*.*'
CHR(0) seperated string of filters e.g.: "Tables" + CHR(0) + "*.dbf" + CHR(0) + "Databases" + CHR(0) + "*.dbc"
you can also pass "" (empty string) to omit the filter values.
- cFileName (optional)
default = empty
The filename that is initially displayed in the dialog box.
- cInitialDirectory (optional)
default = empty
The initial directory. The algorithm for selecting the initial directory varies on different platforms.
Windows 7:
If cInitialDirectory has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
Otherwise, if cFileName contains a path, that path is the initial directory.
Otherwise, if cInitialDirectory is not empty, it specifies the initial directory.
If cInitialDirectory is empty and the current directory contains any files of the specified filter types, the initial directory is the current directory.
Otherwise, the initial directory is the personal files directory of the current user.
Otherwise, the initial directory is the Desktop folder.
Windows 2000/XP/Vista:
If cFileName contains a path, that path is the initial directory.
Otherwise, cInitialDirectory specifies the initial directory.
Otherwise, if the application has used an Open or Save As dialog box in the past, the path most recently used is selected as the initial directory. However, if an application is not run for a long time, its saved selected path is discarded.
If cInitialDirectory is empty and the current directory contains any files of the specified filter types, the initial directory is the current directory.
Otherwise, the initial directory is the personal files directory of the current user.
Otherwise, the initial directory is the Desktop folder.
- cDialogTitle (optional)
default = empty
A string to be placed in the title bar of the dialog box. If this parameter is empty, the system uses the default title (that is, Save As or Open).
- nFlagsEx (optional)
default = 0
if you pass OFN_EX_NOPLACESBAR (1) as nFlagsEx paramter the dialog doesn't show the places bar (the button's on the left for common used directories).
- cCallbackfunction (optional)
If you pass a VFP function name the function will be called when events in the dialog occur.
The function must have to following prototype.FUNCTION OpenFileCallback(lnHwnd, lnControlID, lnCode) ENDFUNC
See dialogs.prg in the example project for more info.
Return Value
-1 if an error occured.
0 if the dialog was aborted.
The entered filename.
See Also
Reference
GetOpenFileName
MessageBoxEx
SHBrowseFolder