ChooseFile

The ChooseFile function creates an Open / Save common dialog box that lets the user specify the drive, directory, and the name of a file to open / save.

string ChooseFile(
  boolean open,
  string defext,
  string filename,
  dword flag,
  string filter,
  dword hwnd
);
 

Parameters

open
Set to true to construct a File Open dialog box or false to construct a File Save As dialog box.
defext
The default filename extension. If the user does not include an extension in the Filename edit box, the extension specified by defext is automatically appended to the filename.
filename
The initial filename that appears in the filename edit box.
flag
A set of bit flags you can use to initialize the dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following 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. 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_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.
OFN_HIDEREADONLY
Hides the Read Only check box.
OFN_NOCHANGEDIR
Restores the current directory to its original value if the user changed the directory while searching for files.
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 filenames. If this flag is used and the user types an invalid path and filename 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 checked initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed.
 
filter
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. The first string in the string pair describes the filter; the second string indicates the file extension to use. Multiple extensions may be specified using ; as the delimiter. The string ends with two | characters, followed by a NULL character.
hwnd
Identifies the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.

Return Values

If the user clicks the OK button, the return value is the full path of the selected file.

Otherwise, the return value is nil.


Example

local flags=orDWORD(OFN_HIDEREADONLY,OFN_OVERWRITEPROMPT)
local filter='Magic Cube Save Files(*.mcsav)|*.mcsav|All Files(*.*)|*.*||'
local filename=wnd.ChooseFile(false,'mcsav',GetAppPath()..'save1',flags,filter)
if (not filename) then return end