xtanxin 发表于 2009-1-22 15:27:24

如何dllcall 调用API函数SHBrowseForFolder,实现选择目录对话框的使用?

本帖最后由 xtanxin 于 2010-1-5 15:43 编辑

SHBrowseForFolder

如何dllcall 调用API函数SHBrowseForFolder,实现选择目录对话框的使用?

sanhen 发表于 2009-1-25 01:06:36

$ret = FileSelectFolder('请选择一个文件夹', '', 4)
ConsoleWrite($ret)

为什么一定要用API呢?

sanhen 发表于 2009-1-25 01:14:05



_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")
    Local $urs = DllStructCreate ("char")
    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 Then Return $res
    $pidl = DllCall ("shell32.dll", "ptr", "SHBrowseForFolder", "ptr", DllStructGetPtr ($ubi))
    If $pidl Then
      $ret = DllCall ("shell32.dll", "int", "SHGetPathFromIDList", _
            "ptr", $pidl, _
            "ptr", DllStructGetPtr ($urs))
      If $ret Then $res = DllStructGetData ($urs, 1)
      DllCall ("ole32.dll", "int", "CoTaskMemFree", "ptr", $pidl)
    EndIf
    DllCall ("ole32.dll", "int", "CoTaskMemFree", "ptr", DllStructGetData ($ubi, 2))
    Return $res
EndFunc

xtanxin 发表于 2009-1-26 20:49:43

还是好人多呀,等了一天没有人回答,终于有了.
坛主,能不能放我到UDF板块呀,
基础的部分我抄抄改改的问题不大,我基本很少需要GUI的
页: [1]
查看完整版本: 如何dllcall 调用API函数SHBrowseForFolder,实现选择目录对话框的使用?