Creates an Open dialog box that lets the user specify the drive, directory, and the name of a file or set of files to open
#include <WinAPIDlg.au3>
_WinAPI_GetOpenFileName ( [$sTitle = "" [, $sFilter = "All files (*.*)" [, $sInitalDir = "." [, $sDefaultFile = "" [, $sDefaultExt = "" [, $iFilterIndex = 1 [, $iFlags = 0 [, $iFlagsEx = 0 [, $hWndOwner = 0]]]]]]]]] )
$sTitle | [optional] string to be placed in the title bar of the dialog box |
$sFilter | [optional] Pairs of filter strings (for example "Text Files (*.txt)|All Files (*.*)") The first string in each pair is a display string that describes the filter (for example, "Text Files") The second string specifies the filter pattern (for example, "*.TXT") To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK") A pattern string can be a combination of valid file name characters and the asterisk (*) wildcard character Do not include spaces in the pattern string. |
$sInitalDir | [optional] String that can specify the initial directory |
$sDefaultFile | [optional] A file name used to initialize the File Name edit control |
$sDefaultExt | [optional] String that contains the default extension |
$iFilterIndex | [optional] Specifies the index of the currently selected filter in the File Types control |
$iFlags | [optional] See Flags in $tagOPENFILENAME information |
$iFlagsEx | [optional] See FlagEx in $tagOPENFILENAME information |
$hWndOwner | [optional] Handle to the window that owns the dialog box. This member can be any valid window handle, or it can be 0 if the dialog box has no owner |
Success: | an array in the following format: [0] - Contains the number of strings [1] - Contains the path selected [2] - Contains file selected [n] - Contains file selected |
Failure: | sets the @error flag to non zero, call _WinAPI_CommDlgExtendedError() to get extended error information. |
$tagOPENFILENAME, _WinAPI_CommDlgExtendedError, _WinAPI_GetSaveFileName
Search GetOpenFileName in MSDN Library.
#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WinAPIDlg.au3>
#include <WindowsConstants.au3>
Global $g_idMemo
_Example_Defaults()
_Example_ExplorerStyleMultiSelect()
_Example_OldStyle()
_Example_ExplorerStyleSingleSelect()
_Example_ExplorerStyle_NoPlaceBar()
Func _Example_Defaults()
Local $hGui, $id_Dialog, $aFile, $sError
; Create GUI
$hGui = GUICreate("GetOpenFileName use defaults", 400, 296)
$g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
$id_Dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $id_Dialog
$aFile = _WinAPI_GetOpenFileName() ; use defaults
If @error Then
$sError = _WinAPI_CommDlgExtendedError()
MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
Else
For $x = 1 To $aFile[0]
MemoWrite($aFile[$x])
Next
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGui)
EndFunc ;==>_Example_Defaults
Func _Example_ExplorerStyleMultiSelect()
Local $hGui, $id_Dialog, $aFile, $sError
; Create GUI
$hGui = GUICreate("GetOpenFileName use Explorer Style (Multi Select)", 400, 296)
$g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
$id_Dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $id_Dialog
$aFile = _WinAPI_GetOpenFileName("My Open File Dialog", _
"Text File (*.txt;*.au3)", ".", @ScriptName, "", 1, _
BitOR($OFN_ALLOWMULTISELECT, $OFN_EXPLORER), 0, $hGui)
If @error Then
$sError = _WinAPI_CommDlgExtendedError()
MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
Else
For $x = 1 To $aFile[0]
MemoWrite($aFile[$x])
Next
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGui)
EndFunc ;==>_Example_ExplorerStyleMultiSelect
Func _Example_OldStyle()
Local $hGui, $id_Dialog, $aFile, $sError
; Create GUI
$hGui = GUICreate("GetOpenFileName use Old Style (Multi Select)", 400, 296)
$g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
$id_Dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $id_Dialog
$aFile = _WinAPI_GetOpenFileName("My Open File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, _
"", 2, $OFN_ALLOWMULTISELECT, 0, $hGui)
If @error Then
$sError = _WinAPI_CommDlgExtendedError()
MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
Else
For $x = 1 To $aFile[0]
MemoWrite($aFile[$x])
Next
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGui)
EndFunc ;==>_Example_OldStyle
Func _Example_ExplorerStyleSingleSelect()
Local $hGui, $id_Dialog, $aFile, $sError
; Create GUI
$hGui = GUICreate("GetOpenFileName use Explorer Style (Single Select)", 400, 296)
$g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
$id_Dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $id_Dialog
$aFile = _WinAPI_GetOpenFileName("My Open File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, _
"", 2, 0, 0, $hGui)
If @error Then
$sError = _WinAPI_CommDlgExtendedError()
MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
Else
For $x = 1 To $aFile[0]
MemoWrite($aFile[$x])
Next
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGui)
EndFunc ;==>_Example_ExplorerStyleSingleSelect
Func _Example_ExplorerStyle_NoPlaceBar()
Local $hGui, $id_Dialog, $aFile, $sError
; Create GUI
$hGui = GUICreate("GetOpenFileName use Explorer Style (Single Select)", 400, 296)
$g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
$id_Dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $id_Dialog
$aFile = _WinAPI_GetOpenFileName("My Open File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, _
"", 2, $OFN_EXPLORER, $OFN_EX_NOPLACESBAR, $hGui)
If @error Then
$sError = _WinAPI_CommDlgExtendedError()
MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
Else
For $x = 1 To $aFile[0]
MemoWrite($aFile[$x])
Next
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete($hGui)
EndFunc ;==>_Example_ExplorerStyle_NoPlaceBar
; Write a line to the memo control
Func MemoWrite($sMessage)
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite