当前位置: 网学 > 编程文档 > VB > 正文

在类中封装目录选择对话框

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式

    你是否在纳闷,在VB公用对话框中怎么没有目录选择对话框呢,事实上在API查看器中也未声明这个API.本例用到的两个API如下

SHBrowseForFolder

    用于浏览文件夹、打印机和网络

SHGetPathFromIDList

    用于将项标识符列表转换为文件系统路径

有了这两个API函数,你就可以构造一个目录选择对话框类以代替VB中的目录控件.类clsGetPath的完整代码如下:

Option Explicit
''API声明部分
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
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 Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Private Const BIF_RETURNONLYFSDIRS = 0
Private Const BIF_DONTGOBELOWDOMAIN = 1
Private Const BIF_STATUSTEXT = 2
Private Const BIF_RETURNFSANCESTORS = 3
Private Const BIF_BROWSEFORCOMPUTER = 4
Private Const BIF_BROWSEFORPRINTER = 5

''变量声明
Private mvarCaption As String
Private mvarhWnd As Long
Private mvarFlags As Integer
Private mvarFolder As Variant

''类的属性
Public Property Let Folder(ByVal vData As Variant)
    mvarFolder = vData
End Property

Public Property Set Folder(ByVal vData As Variant)
    Set mvarFolder = vData
End Property

Public Property Get Folder() As Variant
    If IsObject(mvarFolder) Then
        Set Folder = mvarFolder
    Else
        Folder = mvarFolder
    End If
End Property

Public Property Let Flags(ByVal vData As Integer)
    mvarFlags = vData
End Property

Public Property Get Flags() As Integer
    Flags = mvarFlags
End Property

Public Property Let hwnd(ByVal vData As Long)
    mvarhWnd = vData
End Property

Public Property Get hwnd() As Long
    hwnd = mvarhWnd
End Property

Public Property Let Caption(ByVal vData As String)
    mvarCaption = vData
End Property

Public Property Get Caption() As String
    Caption = mvarCaption
End Property

''类的方法
Public Sub GetFolder()
    Dim bi As BROWSEINFO
    Dim pidl As Long
    Dim ret As String

    ret = String$(255, Chr$(0))

    With bi
        .hOwner = hwnd
        .ulFlags = Flags
        If Caption <> "" Then
  &n
  • 上一篇资讯: VB中实现MD5加密
  • 下一篇资讯: VB编程中的一些经验
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号