FileSaveDialog()函数定义在那里可以找到?
默认的用起总觉得不对劲,如:$var = FileSaveDialog( "输入一个名称.", @DesktopDir, "脚本 (*.au3)|文本文件 (*.txt)", 18, "FileName")
出来的窗口中,不管你选了"au3"还是"txt",返回的还是“FileName”,也就是它返回值根本没有文件类型呀,并且如:$var = FileSaveDialog( "输入一个名称.", @DesktopDir, "脚本 (*.au3)|文本文件 (*.txt)", 18, "FileName.au3"),然后你选文件类型为“txt”,窗口上显示的文件名还是:FileName.au3,而不是:FileName.txt,所以想看看怎么定义的,或者怎么解决这个问题? 基本函数文件驱动器操作里 回复 2# netegg
.......................... 回复 3# happytc
{:face (460):}怎么?不对吗? 回复 4# netegg
那你把这个函数定义帖出来嘛! 不过,说实话,au3默认的FileOpenDialog, FileSaveDialog都不大好用 回复 6# happytc
扩展的在官方有,不过很麻烦 回复 7# netegg
不麻烦吧。下面是我试着写了个,可以实现返回值包含后缀,别的参数跟默认的一样用法
Func _FileSaveDialog($sTitle, $sInitDir, $sFilter='All (*.*)', $iOpt=0, $sDefFile='', $iDefFilter=1, $hWnd=0)
Local $iFileLen = 65536
Local $iFlag = BitOR(BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 16), 3))
If Not StringInStr($sFilter, '|') Then $sFilter &= '|*.*'
$sFilter = StringRegExpReplace($sFilter, '|+', '|')
Local $asFLines = StringSplit($sFilter, '|')
Local $i, $suFilter = ''
For $i = 1 To $asFLines Step 2
If $i < $asFLines Then _
$suFilter &= 'byte[' & StringLen($asFLines[$i]) + 1 & '];char[' & StringLen($asFLines[$i + 1]) + 1 & '];'
Next
Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')
Local $usTitle = DllStructCreate('char[' & StringLen($sTitle) + 1 & ']')
Local $usInitDir = DllStructCreate('char[' & StringLen($sInitDir) + 1 & ']')
Local $usFilter = DllStructCreate($suFilter & 'byte')
Local $usFile = DllStructCreate('char[' & $iFileLen & ']')
Local $usExtn = DllStructCreate('char')
For $i = 1 To $asFLines
DllStructSetData($usFilter, $i, $asFLines[$i])
Next
DllStructSetData($usTitle, 1, $sTitle)
DllStructSetData($usInitDir, 1, $sInitDir)
DllStructSetData($usFile, 1, $sDefFile)
DllStructSetData($usExtn, 1, '')
DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
DllStructSetData($uOFN, 2, $hWnd)
DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
DllStructSetData($uOFN, 7, $iDefFilter)
DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
DllStructSetData($uOFN, 9, $iFileLen)
DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
DllStructSetData($uOFN, 14, $iFlag)
DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))
Local $aRet = DllCall('comdlg32.dll', 'int', 'GetSaveFileName', 'ptr', DllStructGetPtr($uOFN))
If Not IsArray($aRet) Or Not $aRet Then Return SetError(1, 0, "")
Local $sRet = StringStripWS(DllStructGetData($usFile, 1), 3)
Return SetExtended(DllStructGetData($uOFN, 7), $sRet)
EndFunc
本帖最后由 netegg 于 2011-6-17 22:31 编辑
回复 8# happytc $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$var = _FileSaveDialog( "输入一个名称.", $MyDocsFolder, "脚本 (*.aut;*.au3)", 2)
Func _FileSaveDialog($sTitle, $sInitDir, $sFilter='All (*.*)', $iOpt=0, $sDefFile='', $iDefFilter=1, $hWnd=0)
Local $iFileLen = 65536
Local $iFlag = BitOR(BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 16), 3))
If Not StringInStr($sFilter, '|') Then $sFilter &= '|*.*'
$sFilter = StringRegExpReplace($sFilter, '|+', '|')
Local $asFLines = StringSplit($sFilter, '|')
Local $i, $suFilter = ''
For $i = 1 To $asFLines Step 2
If $i < $asFLines Then _
$suFilter &= 'byte[' & StringLen($asFLines[$i]) + 1 & '];char[' & StringLen($asFLines[$i + 1]) + 1 & '];'
Next
Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')
Local $usTitle = DllStructCreate('char[' & StringLen($sTitle) + 1 & ']')
Local $usInitDir = DllStructCreate('char[' & StringLen($sInitDir) + 1 & ']')
Local $usFilter = DllStructCreate($suFilter & 'byte')
Local $usFile = DllStructCreate('char[' & $iFileLen & ']')
Local $usExtn = DllStructCreate('char')
For $i = 1 To $asFLines
DllStructSetData($usFilter, $i, $asFLines[$i])
Next
DllStructSetData($usTitle, 1, $sTitle)
DllStructSetData($usInitDir, 1, $sInitDir)
DllStructSetData($usFile, 1, $sDefFile)
DllStructSetData($usExtn, 1, '')
DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
DllStructSetData($uOFN, 2, $hWnd)
DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
DllStructSetData($uOFN, 7, $iDefFilter)
DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
DllStructSetData($uOFN, 9, $iFileLen)
DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
DllStructSetData($uOFN, 14, $iFlag)
DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))
Local $aRet = DllCall('comdlg32.dll', 'int', 'GetSaveFileName', 'ptr', DllStructGetPtr($uOFN))
If Not IsArray($aRet) Or Not $aRet Then Return SetError(1, 0, "")
Local $sRet = StringStripWS(DllStructGetData($usFile, 1), 3)
Return SetExtended(DllStructGetData($uOFN, 7), $sRet)
EndFunc
对等的例子,先看看显示效果, 具体的返回还没测试,可能是结构的参数没设置对,后缀显示不全 回复 9# netegg
你搞个特别的目录,windows默认是不允许随便访问的 回复 10# happytc
不是啊这个就是帮助里filesavedialog的例子,只是后面的函数换成你的了 哟,这样呀。 默认的,不知道为什么,若我把筛选文件类型写复杂点,都会有问题,如下面的
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$sFilter = "PNG Image (*.png)|*.png|GIF Image (*.gif)|*.gif|JPEG Image (*.jpg)|*.jpg|BMP Image (*.bmp)|*.bmp|"
$sFilter &= "Save Image Type (*.bmp, *.jpg, *.gif, *.png)|*.bmp;*.jpg;*.gif;*.png"
$var = FileSaveDialog("输入一个名称.", $MyDocsFolder, $sFilter, 2) 回复 8# happytc
这代码,看着很熟,这里面90%的代码,我好像在哪看到过,忘记了是在本论坛还是官网。这是借鉴修改别人的吧? 本帖最后由 happytc 于 2011-6-17 23:06 编辑
回复 14# pusofalse
以前写的
肯定借鉴了官网和本站的很多人的代码。
基本我学au3开始,都在官网吸取了无数营养呀
并且我发现我在官网的一马甲发的代码也被别人借用呢,笑……
页:
[1]
2