谁知道用API如何调出目录选择窗口

cuy 2001-06-13 01:34:00
就是像FOXMAIL多个文件一起另存为的时候那样的窗口。
选择驱动程序的时候也有。
是用那个API啊。
DLL 也可以啊。
还有啊GetSaveFileName
这个函数我为什么返回的目录只能反回头8个字符。
其它的部分就找不到了。
...全文
123 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
y1g1y1 2001-06-15
  • 打赏
  • 举报
回复
ygyuan.3322.net
->
下载园地
->
选择目录对话框的源程序
Leemaasn 2001-06-14
  • 打赏
  • 举报
回复
在这里了,
你自己看看吧。VERSION 5.00
Begin VB.Form Form1
Caption = "测试调用“浏览文件夹”对话框"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "打 开"
Height = 495
Left = 1800
TabIndex = 0
Top = 1320
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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
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
Option Explicit

Private Sub Command1_Click()
Dim tmp As BrowseInfo
Dim l As Long
Dim str As String * 255
tmp.hwndOwner = Me.hWnd
l = SHBrowseForFolder(tmp)
' MsgBox str(l)
Call SHGetPathFromIDList(l, str)
MsgBox str
End Sub
'l得到的是函数的返回值,数字,不是文件夹的名称!
》》》》》》》》》》》》》》》》
prefix 2001-06-13
  • 打赏
  • 举报
回复
放一个按钮在窗体上,把下面的代码粘贴到窗体的代码窗口中去:

Option Explicit

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

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

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

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 Sub Command1_Click()
'显示对话框
Dim lpIDList As Long 'Declare Varibles
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "See it?"

With tBrowseInfo
.hWndOwner = Me.hWnd 'Owner Form
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
MsgBox sBuffer
End If

End Sub

运行该程序,点击按钮将弹出选择目录对话框,选择一个目录后点ok将跳出一个msgbox说明你所选的目录。
cuy 2001-06-13
  • 打赏
  • 举报
回复
我在你的主页上没有找到源程序啊。

不太容易搜索啊
DevilXelloss 2001-06-13
  • 打赏
  • 举报
回复
#If UNICODE Then
Public Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListW" (ByVal pidl As Long, ByVal szPath As Long) As Long
#Else
Public Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
#End If
Public Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Public Declare Function SHGetSpecialFolderLocation2 Lib "Shell32" Alias "SHGetSpecialFolderLocation" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As ItemIDList) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BrowseInfo) As Long

Type SHItemID 'mkid
cb As Long 'Size of the ID (including cb itself)
abID As Byte 'The item ID (variable length)
End Type

' The ITEMIDLIST structure defines an element in an item identifier list
' (the only member of this structure is an SHITEMID structure). An item
' identifier list consists of one or more consecutive ITEMIDLIST structures
' packed on byte boundaries, followed by a 16-bit zero value. An application
' can walk a list of item identifiers by examining the size specified in each
' SHITEMID structure and stopping when it finds a size of zero. A pointer
' to an item identifier list, is sometimes called a PIDL (pronounced piddle)
Type ItemIDList 'idl
mkid As SHItemID
End Type

' Contains parameters for the the SHBrowseForFolder function and receives
' information about the folder selected by the user.
Public Type BrowseInfo 'bi

' Handle of the owner window for the dialog box.
hOwner As Long

' Pointer to an item identifier list (an ITEMIDLIST structure) specifying the location
' of the "root" folder to browse from. Only the specified folder and its subfolders
' appear in the dialog box. This member can be NULL, and in that case, the
' name space root (the desktop folder) is used.
pidlRoot As Long

' Pointer to a buffer that receives the display name of the folder selected by the
' user. The size of this buffer is assumed to be MAX_PATH bytes.
pszDisplayName As String

' Pointer to a null-terminated string that is displayed above the tree view control
' in the dialog box. This string can be used to specify instructions to the user.
lpszTitle As String

' Value specifying the types of folders to be listed in the dialog box as well as
' other options. This member can include zero or more of the following values below.
ulFlags As Long

' Address an application-defined function that the dialog box calls when events
' occur. For more information, see the description of the BrowseCallbackProc
' function. This member can be NULL.
lpfn As Long

' Application-defined value that the dialog box passes to the callback function
' (if one is specified).
lParam As Long

' Variable that receives the image associated with the selected folder. The image
' is specified as an index to the system image list.
iImage As Long

End Type

Public Function BrowseForFolder(ByVal hWnd As Long, ByVal Title As String, ByVal flags As BROWSEFORFOLDERFLAGS, ByVal BrowseSpecial As Boolean, ByVal SpecialFolderFlag As SHELLFOLDERS, lpstrBuffer As String, Optional ByVal lpCallbackProc As Long = 0, Optional lpData As Long = 0) As Long
Dim bi As BrowseInfo
Dim idl As ItemIDList
Dim rtn As Long, pidl As Long, Path As String

' the calling app
bi.hOwner = hWnd

' set the folder to limit the browse to in the dialog
' if CurOptIdx% = 0 (Default Browse), bi.pidlRoot would then be Null
If BrowseSpecial Then
rtn = SHGetSpecialFolderLocation2(hWnd, SpecialFolderFlag, idl)
bi.pidlRoot = idl.mkid.cb
End If

If lpCallbackProc <> 0 Then
bi.lpfn = lpCallbackProc
bi.lParam = lpData
End If

' set the banner text
bi.lpszTitle = Title

' set the type of folder to return
' play with these option constants to see what can be returned
bi.ulFlags = flags

' show the browse folder dialog
pidl = SHBrowseForFolder(bi)

Path = Space(512)
rtn = SHGetPathFromIDList(ByVal pidl, ByVal Path)

If rtn Then
' parce & display the folder selection
Path = Trim(Path): Path = IIf(Path = "", " ", Path)
Path = IIf(Asc(Right(Path, 1)) = 0, Left(Path, Len(Path) - 1), Path)
lpstrBuffer = Path
End If

' 释放 OLE 对象占用的内存。
CoTaskMemFree idl.mkid.cb
CoTaskMemFree bi.pidlRoot

BrowseForFolder = rtn
End Function
cuy 2001-06-13
  • 打赏
  • 举报
回复
这事搞定了就给分!
cuy 2001-06-13
  • 打赏
  • 举报
回复
目录我已经找到了奇怪这个函数为什么找不到它的声明。

请问这样的新函数声明和帮助在那里找到啊。

其实现在主要的问题是在这个函数了GetSaveFileName
为什么我用了以后.lpstrFile 只有前十几个字符呢?
y1g1y1 2001-06-13
  • 打赏
  • 举报
回复
ygyuan.go.163.com 有一个很好的源程序!

最新上传的。
Nilaix 2001-06-13
  • 打赏
  • 举报
回复
SHBrowseForFolder
playyuer 2001-06-13
  • 打赏
  • 举报
回复
HOWTO: Use the Common Dialog Control with Multiple Long File Names
http://support.microsoft.com/support/kb/articles/Q198/9/74.asp

HOWTO: Use a Common Dialog File Open Dialog with Win32 API
http://support.microsoft.com/support/kb/articles/Q161/2/86.asp
playyuer 2001-06-13
  • 打赏
  • 举报
回复
1.Common Dialog Control

2.
HOWTO: Select a Directory Without the Common Dialog Control
http://support.microsoft.com/support/kb/articles/Q179/4/97.asp
Leemaasn 2001-06-13
  • 打赏
  • 举报
回复
你等一下,我在别的机子上网。资料不在,等会给你。

1,486

社区成员

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

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