Help Center

AfxOpenFileDialogfunction

Creates an Open dialog box that lets the user specify the drive, directory, and the name of a file or set of files to be opened.

WindowsfunctionAfxWin.incdocumented

Syntax

FUNCTION AfxOpenFileDialog (BYVAL hwndOwner AS HWND, BYREF wszTitle AS WSTRING, BYREF wszFile AS WSTRING, BYREF wszInitialDir AS WSTRING, BYREF wszFilter AS WSTRING, BYREF wszDefExt AS WSTRING, BYVAL pdwFlags AS DWORD PTR = NULL, BYVAL pdwBufLen AS DWORD PTR = NULL) AS DWSTRING

Parameters

NameDescription
hwndOwnerA handle to 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.
wszTitleA string to be placed in the title bar of the dialog box. If this member is NULL, the system uses the default title (that is, Open).
wszFileThe file name used to initialize the File Name edit control.
wszInitialDirThe initial directory. If no initial directory is specified, the dialog will use the current directory.
wszFilterA buffer containing pairs of "\
wszDefExtThe default extension. This extension is appended to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.
pdwFlags\[in, out, optional] 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.
pdwBufLen\[in, out, optional] Maximum length of the returned string containing the selected file or files.

Return value

If the OFN_ALLOWMULTISELECT flag is set and the user selects multiple files, the returned string contains the current directory followed by the file names of the selected files. For Explorer-style dialog boxes, the directory and file name strings are separated by semicolons. If the user selects only one file, the returned string does not have a separator between the path and file name.

Parse the number of ",". If only one, then the user has selected only a file and the string contains the full path. If more, The first substring contains the path and the others the files. If the user has not selected any file, an empty string is returned. On failure, an empty string is returned and, if not null, the pdwBufLen parameter will be filled by the size of the required buffer in characters.

Description

Creates an Open dialog box that lets the user specify the drive, directory, and the name of a file or set of files to be opened. The dialog box uses the Explorer-style user interface.

Example

DIM wszFile AS WSTRING * 260 = "." DIM wszInitialDir AS STRING * 260 = CURDIR DIM wszFilter AS WSTRING * 260 = "BAS files (.BAS)|.BAS|" & "All Files (.)|.|" DIM dwFlags AS DWORD = OFN_EXPLORER OR OFN_FILEMUSTEXIST OR OFN_HIDEREADONLY OR OFN_ALLOWMULTISELECT DIM dws AS DWSTRING = AfxOpenFileDialog(hwnd, "", wszFile, wszInitialDir, wszFilter, "BAS", @dwFlags, NULL)

Reference

  • Include file AfxWin.inc
  • Defined in AfxNova/AfxWin.inc:995
  • Documented in Windows/Windows Procedures.md
  • Topic: Windows Procedures