有人知道通用对话框怎么取得不带文件名的路径吗?
解决方案 »
- 如何在ContextMenuStrip 中嵌入一个CheckedListBox,或者说:把这两个控件组成一个复合控件
- 在用户控件中可以用菜单编辑器添加菜单吗?
- 我这里有个兼职的VB开发项目,实现短信发送WAP发送WAP书签功能
- 紧急求助!在VB中如何使用命令创建一个ACCESS数据库?在线等待......
- 关于数据类型转换的一个问题!
- 请问DataRepeater1控件怎么使用?谢谢
- 【随便聊聊】msdn的使用和经验。来者有分。
- 急~~~~请问:如何判断当前的listview有没有条目选中?最好别用err(在线等待)
- 交VB朋友33676851
- 本人急求拨号上网原程序!help!
- 如何只捕捉刚才插入数据库的那一条记录的主键值?
- 请问为什么在ActiveX control里加入listview,发布IIS后,IE登录后再关闭IE时会出现内存错误bug
Option ExplicitDeclare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" ( _
ByVal pidl As Long, _
ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" ( _
lpBrowseInfo As BROWSEINFO) As Long
Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End TypePrivate Const BIF_RETURNONLYFSDIRS = &H1
Private Const BIF_DONTGOBELOWDOMAIN = &H2Dim xStartPath As StringFunction SelectDir(Optional StartPath As String, Optional Titel As String) As String
Dim iBROWSEINFO As BROWSEINFO
With iBROWSEINFO
.lpszTitle = IIf(Len(Titel), Titel, "ÇëÑ¡ÔñÎļþ¼Ð")
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN
If Len(StartPath) Then
xStartPath = StartPath & vbNullChar
.lpfnCallback = GetAddressOf(AddressOf CallBack)
End If
End With
Dim xPath As String, NoErr As Long: xPath = Space$(512)
NoErr = SHGetPathFromIDList(SHBrowseForFolder(iBROWSEINFO), xPath)
SelectDir = IIf(NoErr, Left$(xPath, InStr(xPath, Chr(0)) - 1), "")
End FunctionFunction GetAddressOf(Address As Long) As Long
GetAddressOf = Address
End FunctionFunction CallBack(ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal pidl As Long, _
ByVal pData As Long) As Long
Select Case Msg
Case 1
Call SendMessage(hWnd, 1126, 1, xStartPath)
Case 2
Dim sDir As String * 64, tmp As Long
tmp = SHGetPathFromIDList(pidl, sDir)
If tmp = 1 Then SendMessage hWnd, 1124, 0, sDir
End Select
End Function
Public Function mkSubDir(ByVal sDirPath As String) As Boolean
On Error GoTo errHandle
Dim astr() As String
Dim i As Long
Dim sTmpPath As String
astr = Split(sDirPath, "\")
sTmpPath = astr(0)
For i = 1 To UBound(astr)
sTmpPath = sTmpPath & "\" & astr(i)
If Dir(sTmpPath, vbDirectory) = "" Then MkDir sTmpPath
Next
Erase astr
mkSubDir = True
Exit Function
errHandle:
mkSubDir = False
End FunctionPrivate Sub Command1_Click()
Dim strDir As String
strDir = SelectDir("C:\", vbNullString) '¼ÙÉè³õʼ·¾¶Îª"C:\"
Caption = strDir
End Sub
Option ExplicitDeclare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" ( _
ByVal pidl As Long, _
ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" ( _
lpBrowseInfo As BROWSEINFO) As Long
Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End TypePrivate Const BIF_RETURNONLYFSDIRS = &H1
Private Const BIF_DONTGOBELOWDOMAIN = &H2Dim xStartPath As StringFunction SelectDir(Optional StartPath As String, Optional Titel As String) As String
Dim iBROWSEINFO As BROWSEINFO
With iBROWSEINFO
.lpszTitle = IIf(Len(Titel), Titel,“请选择文件夹”)
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN
If Len(StartPath) Then
xStartPath = StartPath & vbNullChar
.lpfnCallback = GetAddressOf(AddressOf CallBack)
End If
End With
Dim xPath As String, NoErr As Long: xPath = Space$(512)
NoErr = SHGetPathFromIDList(SHBrowseForFolder(iBROWSEINFO), xPath)
SelectDir = IIf(NoErr, Left$(xPath, InStr(xPath, Chr(0)) - 1), "")
End FunctionFunction GetAddressOf(Address As Long) As Long
GetAddressOf = Address
End FunctionFunction CallBack(ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal pidl As Long, _
ByVal pData As Long) As Long
Select Case Msg
Case 1
Call SendMessage(hWnd, 1126, 1, xStartPath)
Case 2
Dim sDir As String * 64, tmp As Long
tmp = SHGetPathFromIDList(pidl, sDir)
If tmp = 1 Then SendMessage hWnd, 1124, 0, sDir
End Select
End Function
Public Function mkSubDir(ByVal sDirPath As String) As Boolean
On Error GoTo errHandle
Dim astr() As String
Dim i As Long
Dim sTmpPath As String
astr = Split(sDirPath, "\")
sTmpPath = astr(0)
For i = 1 To UBound(astr)
sTmpPath = sTmpPath & "\" & astr(i)
If Dir(sTmpPath, vbDirectory) = "" Then MkDir sTmpPath
Next
Erase astr
mkSubDir = True
Exit Function
errHandle:
mkSubDir = False
End FunctionPrivate Sub Command1_Click()
Dim strDir As String
strDir = SelectDir("C:\", vbNullString) ‘假设初始路径为"C:\"
Caption = strDir
End Sub