_FileSelectFolder("这是API调用示范")
Func _FileSelectFolder ($title, $root = 0, $flags = 0, $hwnd = 0)
Local $ret, $pidl, $res = ''
Local $ubi = DllStructCreate ("hwnd;ptr;ptr;ptr;int;ptr;ptr;int")
Local $utl = DllStructCreate ("char[512]")
Local $urs = DllStructCreate ("char[260]")
Local $ulf = BitOR (BitShift(BitAnd ($flags,1),-9), _
BitShift(BitAnd ($flags,2),-5), _
BitShift(BitAnd ($flags,4),-2))
DllStructSetData ($utl, 1, $title)
DllStructSetData ($ubi, 1, $hwnd)
DllStructSetData ($ubi, 3, DllStructGetPtr($urs))
DllStructSetData ($ubi, 4, DllStructGetPtr($utl))
DllStructSetData ($ubi, 5, $ulf)
$ret = DllCall ("shell32.dll", "ptr", "SHGetSpecialFolderLocation", _
"int", 0 , _
"int", $root , _
"ptr", DllStructGetPtr($ubi, 2))
If $ret[0] Then Return $res
$pidl = DllCall ("shell32.dll", "ptr", "SHBrowseForFolder", "ptr", DllStructGetPtr ($ubi))
If $pidl[0] Then
$ret = DllCall ("shell32.dll", "int", "SHGetPathFromIDList", _
"ptr", $pidl[0], _
"ptr", DllStructGetPtr ($urs))
If $ret[0] Then $res = DllStructGetData ($urs, 1)
DllCall ("ole32.dll", "int", "CoTaskMemFree", "ptr", $pidl[0])
EndIf
DllCall ("ole32.dll", "int", "CoTaskMemFree", "ptr", DllStructGetData ($ubi, 2))
Return $res
EndFunc
|