打开文件用CommonDialog,打开文件夹(目录)用什么

cystudio 2004-07-19 09:29:24
打开文件用CommonDialog,打开文件夹(目录)用什么

就像winamp播放->文件夹那样的打开目录的对话框用的是什么控件
...全文
605 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
faib920 2004-07-20
  • 打赏
  • 举报
回复
Private Const BIF_STATUSTEXT = &H4&
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const WM_USER = &H400
Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
Private Const BFFM_SETSELECTION = (WM_USER + 102)

Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Function GetAddressofFunction(Add As Long) As Long
GetAddressofFunction = Add
End Function

faib920 2004-07-20
  • 打赏
  • 举报
回复
Public Enum EnumRootFolder
fbfDeskTop = &H0
fbfPrograms = &H2
fbfControls = &H3
fbfPrinters = &H4
fbfPersonal = &H5
fbfFavorites = &H6
fbfStartup = &H7
fbfRecent = &H8
fbfSendTo = &H9
fbfBitbucket = &HA
fbfStartMenu = &HB
fbfDesktopDirectory = 16
fbfDrives = &H11
fbfNetWork = &H12
fbfNetHood = &H13
fbfFonts = &H14
fbfTemplates = &H15
End Enum
Public Enum EnumChoose
fbcFolders = &H1
fbcComputers = &H1000
fbcPrinters = &H2000
fbcEverything = &H4000
End Enum

Public Function ChooseFolder(hWnd As Long, Message As String, Seleted As String, Optional RootFolder As EnumRootFolder = EnumRootFolder.fbfDrives, Optional ChooseWho As EnumChoose = EnumChoose.fbcFolders) As Boolean
'选择目录对话框
On Error GoTo er
Dim Nullpos As Integer
Dim lpIDList As Long
Dim res As Long
Dim sPath As String
Dim Binfo As BrowseInfo
Dim RootID As Long
mPath = Seleted
With Binfo
.hWndOwner = hWnd
.lpszTitle = Message
.ulFlags = BIF_STATUSTEXT Or ChooseWho
.pIDLRoot = RootFolder
.lpfnCallback = GetAddressofFunction(AddressOf BrowseCallbackProc)
If RootID <> 0 Then .pIDLRoot = RootID
End With
lpIDList = SHBrowseForFolder(Binfo)
ChooseFolder = IIf(lpIDList <> 0, True, False)
If lpIDList <> 0 Then
sPath = String(260, Chr(0))
res = SHGetPathFromIDList(lpIDList, sPath)
Nullpos = InStr(sPath, vbNullChar)
If Nullpos Then
Seleted = Left(sPath, Nullpos - 1)
End If
End If
Exit Function
er:
ChooseFolder = False
End Function



Public Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
Dim lpIDList As Long
Dim ret As Long
Dim sBuffer As String
On Error Resume Next
Select Case uMsg
Case BFFM_INITIALIZED: Call SendMessageString(hWnd, BFFM_SETSELECTION, 1, mPath)
Case BFFM_SELCHANGED
sBuffer = Space(260)
ret = SHGetPathFromIDList(lp, sBuffer)
If ret = 1 Then Call SendMessageString(hWnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
End Select
BrowseCallbackProc = 0
End Function
reminious 2004-07-20
  • 打赏
  • 举报
回复
楼上正解
starsoulxp 2004-07-20
  • 打赏
  • 举报
回复
Me.CommonDialog1.InitDir = "c:\"
Me.CommonDialog1.ShowOpen
SeeSunSet 2004-07-20
  • 打赏
  • 举报
回复
用script.filesystemobject对象遍历目录.自己写了生成目录树也行啊.
online 2004-07-19
  • 打赏
  • 举报
回复
http://www.yesky.com/20011026/202297.shtml
这里有比较详细的解释

to 楼上
你去下载一个api guide或者去google搜索

以后我会增加注释的,谢谢提醒
helanshan 2004-07-19
  • 打赏
  • 举报
回复
致:龙卷风V2.0
每次看到你回帖都是:
通篇的API
通篇的没有注释
通篇的看不懂
连个学习的机会也没有啊!1
online 2004-07-19
  • 打赏
  • 举报
回复
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Private Declare Function SHGetSpecialFolderLocation Lib _
"shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
As Long, pIdl As ITEMIDLIST) As Long

Private Declare Function SHGetFileInfo Lib "Shell32" Alias _
"SHGetFileInfoA" (ByVal pszPath As Any, ByVal _
dwFileAttributes As Long, psfi As SHFILEINFO, ByVal _
cbFileInfo As Long, ByVal uFlags As Long) As Long

Private Declare Function ShellAbout Lib "shell32.dll" Alias _
"ShellAboutA" (ByVal hwnd As Long, ByVal szApp As _
String, ByVal szOtherStuff As String, ByVal hIcon As Long) _
As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pIdl As Long, ByVal _
pszPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)

Const MAX_PATH = 260

Private Type SHITEMID
cb As Long
abID() As Byte
End Type

Private Type ITEMIDLIST
mkid As SHITEMID
End Type

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 Type SHFILEINFO
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * MAX_PATH
szTypeName As String * 80
End Type
Private Function GetFolderValue(wIdx As Integer) As Long
If wIdx < 2 Then
GetFolderValue = 0
ElseIf wIdx < 12 Then
GetFolderValue = wIdx
Else
GetFolderValue = wIdx + 4
End If
End Function

Private Sub Command1_Click()
Dim BI As BROWSEINFO
Dim nFolder As Long
Dim IDL As ITEMIDLIST
Dim pIdl As Long
Dim sPath As String
Dim SHFI As SHFILEINFO
Dim m_wCurOptIdx As Integer
Dim txtPath As String
Dim txtDisplayName As String

With BI
.hOwner = Me.hwnd
nFolder = GetFolderValue(m_wCurOptIdx)

If SHGetSpecialFolderLocation(ByVal Me.hwnd, ByVal nFolder, IDL) = NOERROR Then
.pidlRoot = IDL.mkid.cb
End If

.pszDisplayName = String$(MAX_PATH, 0)
.lpszTitle = "Browsing is limited to: "
.ulFlags = 0
End With

txtPath = ""
txtDisplayName = ""

pIdl = SHBrowseForFolder(BI)

If pIdl = 0 Then Exit Sub
sPath = String$(MAX_PATH, 0)
SHGetPathFromIDList ByVal pIdl, ByVal sPath

txtPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
txtDisplayName = Left$(BI.pszDisplayName, _
InStr(BI.pszDisplayName, vbNullChar) - 1)

SHGetFileInfo ByVal pIdl, 0&, SHFI, Len(SHFI), _
SHGFI_PIDL Or SHGFI_ICON Or SHGFI_SMALLICON

SHGetFileInfo ByVal pIdl, 0&, SHFI, Len(SHFI), _
SHGFI_PIDL Or SHGFI_ICON
CoTaskMemFree pIdl
MsgBox "你选择的文件夹是" + Chr(13) + Chr(10) + txtPath
End Sub

lgs666 2004-07-19
  • 打赏
  • 举报
回复
'用CommonDialog控件

Private Sub Command1_Click()
Me.CommonDialog1.InitDir = "c:\"
Me.CommonDialog1.ShowOpen
End Sub

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧