Development Topics > Miscellaneous Topics > GUI Extensions

Displaying a File Open/Save Dialog

In some applications it may be useful to be able to display a standard Windows file open (or save) dialog box to input the name of a file. To do so, use the following:

xcall MIAMEX, MX_GETOFD, fpath, filter, title, flags {,defext {,fname {,type}}}

Parameters

fpath (S,100+)

On input, may contain the initially suggested (default) filename or directory. On return, contains the complete filespec sele cted.

filter (String)

A set of pairs of strings, concatenated all together using pipe (“|”) characters for delimiters, determining which files will be displayed in the dialog box. The first string in each pair is descriptive, and will display in the “Files of Type” area of the dialog box. The second string in each pair is a wildcard specification for that kind of file. If you have more than one wildcard spec for a single descriptive name, separate them with semicolons. For example:

Filter="Data files|*.dat|Text files|*.txt;*.lst"

Note that the “Files of Type” is actually a drop-down box, and that in this example, “Data files” would show as the initial selection, with “Text Files” being the next choice. If you want them all to appear together, then specify just one pair of strings, e.g.:

Filter="Images (*.pcx, *.jpg, *.bmp)|*.pcx;*.jpg;*.bmp"

title (String)

Will appear in the title bar of the dialog. If left blank, “Open” will be displayed.

flags (Numeric)

May contain any combination of the following. On return, may be updated to reflect the selection.

Flags

Description

1

Read-only checkbox initially set

4

Hides the read-only checkbox

256

Don’t force filename to contain only valid chars.

512

Allow multiple file selection. (Successive names will be appended to end of Fpath parameter, separated by spaces.)

1024

Set on return if file extension selected differs from Defext.

2048

Directory must exist.

4096

Don’t allow filenames that don’t exist.

8192

Prompt to confirm if non-existent filename entered.

32768

Set on return if file not read-only and directory is writeable.

131072

Disable network button.

33554432

(W2000) Don’t add to recent files list.

 

defext (Optional, string)

Default file extension. Don’t include the period. If specified, and the user types a filename with no extension, this will be appended to the return Fpath and File parameters.

Fname (Optional, string)

As a convenience, this will return just the filename and extension without the full path. Note, however, that it is not necessarily in the directory you initially specified.

type (Optional, numeric)

If specified and set to 1, the dialog will be a “Save As” dialog instead of a “File Open” dialog. The two dialog types are pretty much the same, except for some verbiage and some common-sense differences (such as not being able to select multiple files in a “Save As” dialog.)

The file path returned by this function is (obviously) in native Windows rather than AMOS format. But this should not present any obstacle to opening the file since AlphaBASIC and most subroutines accept native filespecs wherever they accept AMOS filespecs. Even many LIT commands will accept native filespecs, but in that case they must be enclosed in quotes (e.g. VUE “c:\winnt\lmosts”)