找回密码
 加入
搜索
查看: 1768|回复: 3

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

[复制链接]
发表于 2009-1-22 15:27:24 | 显示全部楼层 |阅读模式
本帖最后由 xtanxin 于 2010-1-5 15:43 编辑

SHBrowseForFolder

如何dllcall 调用API函数SHBrowseForFolder,实现选择目录对话框的使用?
发表于 2009-1-25 01:06:36 | 显示全部楼层
$ret = FileSelectFolder('请选择一个文件夹', '', 4)
ConsoleWrite($ret)

为什么一定要用API呢?
发表于 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[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
 楼主| 发表于 2009-1-26 20:49:43 | 显示全部楼层
还是好人多呀,等了一天没有人回答,终于有了.
坛主,能不能放我到UDF板块呀,
基础的部分我抄抄改改的问题不大,我基本很少需要GUI的
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-4 03:54 , Processed in 0.070664 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表