File Dialogs help

Real API_FileDialog_Prepare (String Filter, String Initial file, String Initial directory, String Default extension);

This function sets option for an API_FileDialog_OpenFile or API_FileDialog_SaveFile call.
The filter is just like get_open_filename, for example "All files (*.*)|*.*".

Return value:
Returns 1.
String API_FileDialog_OpenFile (Real Flags, Real Initial filter index, String Dialog title, Real Owner Window Handle);

This function shows an open file dialog.

The following flags are used:

OFN_ALLOWMULTISELECT
Specifies that the File Name list box allows multiple selections.
Use API_FileDialog_GetNumFiles to get the number of files, if this value is greater than 1, use API_FileDialog_GetFile to get the name of each file.
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. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open. If you use this flag with the OFN_ALLOWMULTISELECT flag, the dialog box allows the user to specify only one nonexistent 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. To retrieve the location of this directory, call the SHGetSpecialFolderLocation function with the CSIDL_RECENT flag.
OFN_ENABLESIZING
Windows 2000/XP, Windows 98/Me: Enables the Explorer-style dialog box to be resized using either the mouse or the keyboard. By default, the Explorer-style Open and Save As dialog boxes allow the dialog box to be resized regardless of whether this flag is set. The old-style dialog box does not permit resizing.
OFN_EXPLORER
Indicates that any customizations made to the Open or Save As dialog box use the new Explorer-style customization methods.
OFN_EXTENSIONDIFFERENT
Specifies that the user typed a file name extension that differs from the extension specified by the default extension.
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_HIDEREADONLY
Hides the Read Only check box.
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_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_NOVALIDATE
Specifies that the common dialog boxes allow invalid characters in the returned file name.
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.
OFN_SHAREAWARE
Specifies that if a call to the OpenFile function fails because of a network sharing violation, the error is ignored and the dialog box returns the selected file name.

Return value:
Returns the filename.


String API_FileDialog_SaveFile (Real Flags, Real Initial filter index, String Dialog title, Real Owner Window Handle);

This function shows a save file dialog.

The flags are the same of API_FileDialog_OpenFile.

Return value:
Returns the filename.
Real API_FileDialog_GetNumFiles ();

This function returns the number of selected files when the OFN_ALLOWMULTISELECT flag was used.

Return value:
Returns the the number of selected files.
String API_FileDialog_GetFile (Real Index);

When argument0 is set to 0, this function returns the directory of all the selected files.
When argument0 is greater than 0, this function returns the filename of the specified index, for example 1 is the first file, 2 is the second and go on ...

This function fails when the value returned by API_FileDialog_GetNumFiles is smaller than 2.

Return value:
Returns the directory or file name.

Example code:

API_FileDialog_Prepare ("All files (*.*)|*.*|Text files (*.txt)|*.txt","test.txt","c:\",".txt"); // Prepares settings

res = API_FileDialog_OpenFile (OFN_EXPLORER|OFN_ALLOWMULTISELECT|OFN_LONGNAMES,2,"Open some stupid file",Win); // Shows an open file dialog.

NumFiles = API_FileDialog_GetNumFiles (); // Returns the number of selected files

if (NumFiles > 1)
{
show_message (API_FileDialog_GetFile (0)); // Shows the directory name.
Cur = 0;

while (Cur < NumFiles)
{
Cur += 1;
show_message (API_FileDialog_GetFile (Cur)); // Shows the file name
}
}




Return to help index