OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Using File Open common dialog boxes

The file open common dialog box serves as a consistent replacement for the many different types of dialog boxes applications have used to open files.

TOpenSaveDialog::TData has several members you must initialize before constructing the dialog box object. You can either initialize them by assigning values, or you can use TOpenSaveDialog::TData 's constructor, which takes the most common parameters, Flags, Filter, CustomFilter, InitialDir, and DefExt, with default arguments of zero.

TData memberTypeDescription
FileNamechar*The selected file name. On input, it specifies the default file name. On output, it contains the selected file name.
Filterchar*The file name filters and filter patterns. Each filter and filter pattern is in the form filter|filter pattern|... where filter is a text string that describes the filter and filter pattern is a DOS wildcard file name. You can repeat filter and filter pattern for as many filters as you need. You must separate them with | characters.
CustomFilterchar*Lets you specify custom filters.
FilterIndexintSpecifies which of the filters specified in Filter should be displayed by default.
InitialDirchar*The directory to be displayed on opening the file dialog box. Use zero for the current directory.
DefExtchar*Default extension appended to FileName if the user does not type an extension. If DefExt is zero, no extension is appended.

In this example, a file-open common dialog box prompts the user for a file name. If an error occurred (Execute returns IDCANCEL and Error returns nonzero), a message box is displayed.

void TCommDlgWnd::CmFileOpen()
{
TFileOpenDialog::TData FilenameData
"All Files (*.*)|*.*|Text Files (*.txt)|*.txt|",
0, "", "*");
if (TFileOpenDialog(this, FilenameData).Execute() != IDOK) {
if (FilenameData.Errval)
{
char msg[50];
wsprintf(msg, "GetOpenFileName returned Error #%ld", Errval);
MessageBox(msg, "WARNING", MB_OK | MB_ICONSTOP);
}
}
}

See Also