创建保存对话框,让用户保存文件到指定的驱动器,目录和文件名
#Include <WinAPI.au3>
_WinAPI_GetSaveFileName( [$sTitle = "" [, $sFilter = "All files (*.*)" [, $sInitalDir = "." [, $sDefaultFile = "" [, $sDefaultExt = "" [, $iFilterIndex = 1 [, $iFlags = 0 [, $iFlagsEx = 0 [, $hwndOwner = 0]]]]]]]]])
$sTitle | [可选参数] 对话框的标题栏字符串 |
$sFilter | [可选参数] 双过滤字符串 (例如 "文本文件 (*.txt)|全部文件 (*.*)") 第一个字符串描述过滤器显示字符串 (例如: "文本文件") 第二个字符串指定过滤模式 (例如: "*.TXT") 要指定多个过滤器模式的显示字符串,使用分号分隔(例如: "*.TXT;*.DOC;*.BAK") 模式串由有效文件名和星号通配符 (*) 组合 模式串不包括空格. |
$sInitalDir | [可选参数] 指定初始目录 |
$sDefaultFile | [可选参数] 编辑控件中文件名使用初始化文件名 |
$sDefaultExt | [可选参数] 包含默认扩展名的字符串 |
$iFilterIndex | [可选参数] 指定文件类型控件中当前选定过滤器的索引 |
$iFlags | [可选参数] 见 $tagOPENFILENAME 结构中 Flags 的信息 |
$iFlagsEx | [可选参数] 见 $tagOPENFILENAME 结构中 FlagEx 信息 |
$hwndOwner | [可选参数] 拥有对话框的窗口句柄.可以是任何有效的窗口句柄;或为 0, 表示对话框没有属主 |
成功: | 返回数组格式如下: |
[0] - 数量字符串 (2) | |
[1] - 路径选择 | |
[2] - 选定的文件 | |
失败: | 返回数组 [0] 为 0 |
在MSDN中搜索
#include <StructureConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global $iMemo
_Example_Defaults()
_Example_ExplorerStyle()
_Example_OldStyle()
_Example_ExplorerStyle_NoPlaceBar()
Func _Example_Defaults()
Local $hGui, $btn_dialog, $aFile, $sError
; 创建 GUI
$hGui = GUICreate("GetSaveFileName use defaults", 400, 296)
$iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$btn_dialog = GUICtrlCreateButton("Save Dialog", 155, 270, 90, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case $btn_dialog
$aFile = _WinAPI_GetSaveFileName() ; use defaults
If $aFile[0] = 0 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_ExplorerStyle()
Local $hGui, $btn_dialog, $aFile, $sError
; 创建 GUI
$hGui = GUICreate("GetSaveFileName use Explorer Style", 400, 296)
$iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$btn_dialog = GUICtrlCreateButton("Save Dialog", 155, 270, 90, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case $btn_dialog
$aFile = _WinAPI_GetSaveFileName("My Save File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", _
"", "au3", 2, 0, 0, $hGui)
If $aFile[0] = 0 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
Func _Example_OldStyle()
Local $hGui, $btn_dialog, $aFile, $sError
; 创建 GUI
$hGui = GUICreate("GetSaveFileName use Old Style", 400, 296)
$iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$btn_dialog = GUICtrlCreateButton("Save Dialog", 155, 270, 90, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case $btn_dialog
$aFile = _WinAPI_GetSaveFileName("My Save File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", "", _
"", 2, $OFN_ALLOWMULTISELECT, 0, $hGui)
If $aFile[0] = 0 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_ExplorerStyle_NoPlaceBar()
Local $hGui, $btn_dialog, $aFile, $sError
; 创建 GUI
$hGui = GUICreate("GetSaveFileName use Explorer Style No Place Bar", 400, 296)
$iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$btn_dialog = GUICtrlCreateButton("Save Dialog", 155, 270, 90, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case $btn_dialog
$aFile = _WinAPI_GetSaveFileName("My Save File Dialog", _
"Text File (*.txt)|AutoIt File (*.au3)", ".", "", _
"", 2, 0, $OFN_EX_NOPLACESBAR, $hGui)
If $aFile[0] = 0 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
; 写入一行到 memo 控件
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite