您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:中文资料 >> 系统API
指定文件夹
  资料类型: 系统API 上传时间: 2001-02-21 阅读次数: 4294



指定文件夹

大家看仔细了,是指定文件夹,不是指定文件。指定文件夹很简单,用通用对话框就行了。但是指定文件就不同了。下面是
实现的方法。

声明

Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260



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

Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long

Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

代码

Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String

Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo


With udtBI
.hWndOwner = hWndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With

lpIDList = SHBrowseForFolder(udtBI)

If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)

If iNull Then
sPath = Left$(sPath, iNull - 1)
End If

End If

BrowseForFolder = sPath

End Function

用法

sDirectoryName = BrowseForFolder(Me.hWnd, "请选择目录")

推荐给朋友 点 评( 4 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.在VB中使用API函数 (之一)
2.怎样用VB在应用程序中调用API
3.在VB中使用API函数 (之二)
4.在VB中使用API函数 (之三)
5.在VB中使用API函数 (之五)
6.在VB中使用API函数 (之四)
7.在VB中用API实现多媒体
8.如何提高调用WINDOWS API函数编程技巧
9.在VB中控制Ctrl+Del+Alt键
10.用API函数改进ListView控件的显示效果
   
   
  评论:
  1.指定了文件夹也就指定了文件了哈~...
  2.什么东西, 麻烦
  3.哪位朋友有中文MSDN,请帮帮忙?
  4.上电脑城买一套盗版的不就行了吗?
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号