设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2801|回复: 9
打印 上一主题 下一主题

Presenting a List of Directories to a User using the Windows Shell Browse for

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2005-8-5 20:01:00 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
标题resenting a List of Directories to a User using the Windows Shell Browse for Folder Dialog

原作者:ATTAC Consulting Group

You can provide Users with a simple Directory dialog rather than using the standard File Open or File Save As dialogs from the common dialog suite which shows both files and directories. To do this you use the Directory dialog built into the Shell OLE container. Here's the code to do it:

In the declarations page of a module, add the following declares (an "_" means line continuation): Type shellBrowseInfo

    hWndOwner      As Long

    pIDLRoot       As Long

    pszDisplayName As Long

    lpszTitle      As String

    ulFlags        As Long

    lpfnCallback   As Long

    lParam         As Long

    iImage         As Long

End Type



Const BIF_RETURNONLYFSDIRS = 1

Const MAX_PATH = 260



Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)

Declare Function SHBrowseForFolder Lib "shell32" (lpbi As shellBrowseInfo) As Long

Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _

         ByVal lpBuffer As String) As Long



Then use the following function, supplying it the title you want to use for the dialog, and the handle of the calling form. (use the Me.hwnd property of the form): Public Function GetFolder(dlgTitle As String, Frmhwnd as Long) As String



    Dim intNullChr As Integer

    Dim lngIDList As Long

    Dim lngResult As Long

    Dim strFolder As String

    Dim BI As shellBrowseInfo



    With BI

        .hWndOwner = Frmhwnd

        .lpszTitle = dlgTitle

        .ulFlags = BIF_RETURNONLYFSDIRS

    End With



    lngIDList = SHBrowseForFolder(BI)

    If lngIDList Then

        strFolder = String$(MAX_PATH, 0)

        lngResult = SHGetPathFromIDList(lngIDList, strFolder)

        Call CoTaskMemFree(lngIDList)        'this frees the ole pointer to lngIDlist

        intNullchr = InStr(strFolder, vbNullChar)

        If intNullchr Then

            strFolder = Left$(strFolder, intNullChr - 1)

        End If

    End If



    GetFolder = strFolder



End FunctionThis function will return the path to the folder selected, so long as it is not a system folder such as the printers folder.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-3 00:04 , Processed in 0.195277 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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