Function Reference


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

#include <WinAPIDlg.au3>
_WinAPI_OpenFileDlg ( [$sTitle = '' [, $sInitDir = '' [, $sFilters = '' [, $iDefaultFilter = 0 [, $sDefaultFilePath = '' [, $sDefaultExt = '' [, $iFlags = 0 [, $iFlagsEx = 0 [, $pOFNProc = 0 [, $pData = 0 [, $hParent = 0]]]]]]]]]]] )


$sTitle [optional] A string to be placed in the title bar of the dialog box.
If this parameter is empty string (Default), the system uses the default title (that is, "Open").
$sInitDir [optional] The initial directory.
$sFilters [optional] The pairs of filter strings (for example, "Text Files (*.txt)"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.txt;*.doc;*.bak").
Do not include spaces in the pattern. To specify multiple groups of filters, use the "|" character as a delimiter (for example, "Text Files (*.txt)|All Files (*.*)").
If this parameter is omitted or an empty string (Default), the dialog box does not display any filters.
$iDefaultFilter [optional] The 1-based index of the currently selected filter to initialize the combo box control.
$sDefaultFilePath [optional] The file name to initialize the edit control.
$sDefaultExt [optional] The default extension that appends 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 parameter is empty string (Default), no extension is appended.
$iFlags [optional] A set of bit flags you can use to initialize the dialog box.
This parameter can be 0 or combination of the following values.
$iFlagsEx [optional] A set of bit flags you can use to initialize the dialog box. It can be 0 or the following value:
$pOFNProc [optional] A pointer to a hook procedure. This parameter is ignored unless the $OFN_ENABLEHOOK flag is set.
$pData [optional] Application-defined data pointer that the system passes to the hook procedure.
$hParent [optional] A handle to the parent window for the dialog box.

Return Value

Success: the full path of the input file if the $OFN_ALLOWMULTISELECT flag is not set, otherwise always an array of paths.
    The zeroth array element contains the number of files.
Failure: sets the @error flag to non-zero, @extended flag may contain the dialog box error code ($CDERR_* or $FNERR_*).


Constants are defined WinAPIConstants.au3.

Call _WinAPI_GetExtended() to retrieve internal $tagOPENFILENAME structure containing the user's selection information after closing the dialog box.

If you use a hook, you can not preserve the UI of the dialog box like in Windows Vista or later.



See Also

Search GetOpenFileName in MSDN Library.


#include <WinAPIDlg.au3>

; Single file selection (returns the fully qualified path)
Local $sFile = _WinAPI_OpenFileDlg('', @WorkingDir, 'AutoIt v3 Scripts (*.au3)|All Files (*.*)', 1, '', '', BitOR($OFN_PATHMUSTEXIST, $OFN_FILEMUSTEXIST, $OFN_HIDEREADONLY))
If Not @error Then
        ConsoleWrite($sFile & @CRLF)

; Multiple file selection (returns an array)
$sFile = _WinAPI_OpenFileDlg('', @WorkingDir, 'AutoIt v3 Scripts (*.au3)|All Files (*.*)', 1, '', '', BitOR($OFN_PATHMUSTEXIST, $OFN_FILEMUSTEXIST, $OFN_HIDEREADONLY, $OFN_ALLOWMULTISELECT, $OFN_EXPLORER))
If Not @error Then
        ConsoleWrite('--------------------------------------------------' & @CRLF)
        For $i = 1 To $sFile[0]
                ConsoleWrite($sFile[$i] & @CRLF)