| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1408 人关注过本帖
标题:[求助]如何点击按钮可以选择文件夹
只看楼主 加入收藏
noctune
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-6-8
收藏
得分:0 

不用了 用API (SHBrowseForFolder函数) 就搞定了啊

给你代码
一个按钮 cmdViewFolder 一个文本框 txtPath

[CODE]
Option Explicit

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

Const BIF_RETURNONLYFSDIRS = &H1

Private Pidl As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal Pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long


Private Sub cmdViewFolder_Click()
Dim BI As BROWSEINFO
Dim lRtn As Long
Dim lPidl As Long
Dim sFPath As String
Dim iPos As Integer

'句柄
BI.hOwner = Me.hWnd
'展开根目录
BI.pidlRoot = 0&
'列表框标题
BI.lpszTitle = "请选择软件安装路径:"
'规定只能选择文件夹,其他无效
BI.ulFlags = BIF_RETURNONLYFSDIRS
'调用API函数显示列表框
lPidl = SHBrowseForFolder(BI)
'利用API函数获取返回的路径
sFPath = Space$(512)

lRtn = SHGetPathFromIDList(ByVal lPidl&, ByVal sFPath)

If lRtn Then
iPos = InStr(sFPath, Chr$(0))
txtPath.Text = Left(sFPath, iPos - 1)
Else
txtPath.Text = ""
End If
End Sub
[/CODE]


世界上有两种人:懂二进制的和不懂二进制的。
2006-12-01 13:04
快速回复:[求助]如何点击按钮可以选择文件夹
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021577 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved