精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓高手出招: 玩转VB〓〓>>Re:在VB中如何调出浏览文件夹对话框

主题:Re:在VB中如何调出浏览文件夹对话框
发信人: nyxi(南野秀一)
整理人: winsy(2003-03-18 09:15:37), 站内信件
【 在 liuzhong72 的大作中提到:】
:是这样的对话框:只要浏览文件夹,不显示文件夹中的文件,按确定后将返回文件夹的路径。
:......
一个例子:
Option Explicit
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (LpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDlist Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Type BROWSEINFO
  hOwner As Long
  pidlroot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lparam As Long
  iImage As Long
End Type
Private Function GetFolder(ByVal hWnd As Long, Optional Title As String) As String
    Dim bi As BROWSEINFO
    Dim pidl As Long
    Dim folder As String
    folder = Space(255)
With bi
   If IsNumeric(hWnd) Then .hOwner = hWnd
   .ulFlags = BIF_RETURNONLYFSDIRS
   .pidlroot = 0
   If Title <> "" Then
      .lpszTitle = Title & Chr$(0)
   Else
      .lpszTitle = "选择目录" & Chr$(0)
    End If
End With

pidl = SHBrowseForFolder(bi)
If SHGetPathFromIDlist(ByVal pidl, ByVal folder) Then
    GetFolder = Left(folder, InStr(folder, Chr$(0)) - 1)
Else
    GetFolder = ""
End If
End Function

Private Sub Command1_Click()
    Text1.Text = GetFolder(Me.hWnd, "选择解压目录")
End Sub



----

I hope that in time you will find
What you long for love 
That's written in the stars
When you finally leave
I think you will see it
Somewhere in my broken heart
    

[关闭][返回]