转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
VB用API实现各种对话框(总结)         ★★★★

VB用API实现各种对话框(总结)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2178 更新时间:2009/4/23 15:42:21
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type
''''/结构说明: _
          hOwner 调用这个对话框的窗口的句柄 _
          pidlRoot 指向你希望浏览的最上面的文件夹的符列表 _
          pszDisplayName 用于保存用户所选择的文件夹的显示名的缓冲区 _
          lpszTitle 浏览对话框的标题 _
          ulFlags  决定浏览什么的标志(见下) _
          lpfn  当事件发生时对话框调用的回调函数的地址.可将它设定为NULL _
          lparam 若定义了回调函数,则为传递给回调函数的值 _
          iImage As Long  保存所选文件夹映像索引的缓冲区 _
ulFlags参数(见下:)
Private Const BIF_RETURNONLYFSDIRS = &H1     ''''仅允许浏览文件系统文件夹
Private Const BIF_DONTGOBELOWDOMAIN = &H2    ''''利用这个值强制用户仪在网上邻居的域级别


Private Const BIF_STATUSTEXT = &H4           ''''在选择对话中显示状态栏
Private Const BIF_RETURNFSANCESTORS = &H8    ''''返回文件系统祖先
Private Const BIF_BROWSEFORCOMPUTER = &H1000 ''''允许浏览计算机
Private Const BIF_BROWSEFORPRINTER = &H2000  ''''允许游览打印机文件夹
''''/--------------------------------------------------------------------------------
Dim FontInfo As SmFontAttr       ''''字体
''''/--------------------------------------------------------------------------------

Private Function GetFolderValue(wIdx As Integer) As Long
    If wIdx < 2 Then
      GetFolderValue = 0
    ElseIf wIdx < 12 Then
      GetFolderValue = wIdx
    Else
      GetFolderValue = wIdx + 4
    End If
End Function
''''
Private Function GetReturnType() As Long
  Dim dwRtn As Long
  dwRtn = dwRtn Or BIF_RETURNONLYFSDIRS
  GetReturnType = dwRtn
End Function
''''
''''文件夹选择对话框
''''函数:SaveFile
''''参数:Title    设置对话框的标签.
''''     hWnd     调用此函数的HWND
''''     FolderID SmBrowFolder枚举(默认:我的电脑).
''''返回值:String 文件夹路径.
''''例子:
Public Function GetFolder(Optional Title As String, _
                          Optional hWnd As Long, _
                          Optional FolderID As SmBrowFolder = MyComputer) As String
  Dim Bi As BROWSEINFO
  Dim Pidl As Long
  Dim Folder As String
  Dim IDL As ITEMIDLIST
  Dim nFolder As Long
  Dim ReturnFol As String
  Dim Fid As Integer
 
  Fid = FolderID
  Folder = String$(255, Chr$(0))
  With Bi
       .hOwner = hWnd
       nFolder = GetFolderValue(Fid)
       If SHGetSpecialFolderLocation(ByVal hWnd, ByVal nFolder, IDL) = NoError Then
          .pidlRoot = IDL.mkid.cb
       End If
       .pszDisplayName = String$(MAX_PATH, Fid)
   
       If Len(Title) > 0 Then
         .lpszTitle = Title & Chr$(0)
       Else
         .lpszTitle = "请选择文件夹:" & Chr$(0)
       End If
  
      .ulFlags = GetReturnType()
  End With
 
  Pidl = SHBrowseForFolder(Bi)
  ''''/返回所选的文件夹路径
  If SHGetPathFromIDList(ByVal Pidl, ByVal Folder) Then
     ReturnFol = Left$(Folder, InStr(Folder, Chr$(0)) - 1)
     If Right$(Trim$(ReturnFol), 1) <> "\" Then ReturnFol = ReturnFol & "\"
     GetFolder = ReturnFol
  Else
    GetFolder = ""
  End If
End Function
''''
''''文件保存对话框
''''函数:SaveFile
''''参数:WinHwnd   调用此函数的HWND
''''     BoxLabel  设置对话框的标签.
''''     StartPath 设置初始化路径.
''''     FilterStr 文件过滤.
''''     Flag      标志.(参考MSDN)
''''返回值:String 文件名.
''''例子:
Public Function SaveFile(WinHwnd As Long, _
                         Optional BoxLabel As String = "", _
                         Optional StartPath As String = "", _
                         Optional FilterStr = "*.*|*.*", _
                         Optional Flag As Variant = &H4 Or &H200000) As String
  Dim Rc As Long
  Dim pOpenfilename As OPENFILENAME
  Dim Fstr1() As String
  Dim Fstr As String
  Dim I As Long
  Const MAX_Buffer_LENGTH = 256
 
  On Error Resume Next
 
  If Len(Trim$(StartPath)) > 0 Then
     If Right$(StartPath, 1) <> "\" Then StartPath = StartPath & "\"
     If Dir$(StartPath, vbDirectory + vbHidden) = "" Then
        StartPath = App.Path
     End If
  Else
     StartPath = App.Path
  End If
  If Len(Trim$(FilterStr)) = 0 Then
     Fstr = "*.*|*.*"
  End If
  Fstr1 = Split(FilterStr, "|")
  For I = 0 To UBound(Fstr1)
      Fstr = Fstr & Fstr1(I) & vbNullChar
  Next
  ''''/--------------------------------------------------
  With pOpenfilename
       .hwndOwner = WinHwnd
       .hInstance = App.hInstance
       .lpstrTitle = BoxLabel
       .lpstrInitialDir = StartPath
       .lpstrFilter = Fstr
       .nFilterIndex = 1
       .lpstrDefExt = vbNullChar & vbNullChar
       .lpstrFile = String(MAX_Buffer_LENGTH, 0)
       .nMaxFile = MAX_Buffer_LENGTH - 1
       .lpstrFileTitle = .lpstrFile
       .nMaxFileTitle = MAX_Buffer_LENGTH
       .lStructSize = Len(pOpenfilename)
       .flags = Flag
  End With
  Rc = GetSaveFileName(pOpenfilename)
  If Rc Then
     SaveFile = Left$(pOpenfilename.lpstrFile, pOpenfilename.nMaxFile)
  Else
    SaveFile = ""
  End If
End Function

''''
''''文件打开对话框
''''函数:OpenFile
''''参数:WinHwnd   调用此函数的HWND
''''     BoxLabel  设置对话框的标签.
''''     StartPath 设置初始化路径.
''''     FilterStr 文件过滤.
''''     Flag      标志.(参考MSDN)
''''返回值:String 文件名.
''''例子:
Public Function OpenFile(WinHwnd As Long, _
                         Optional BoxLabel As String = "", _
                         Optional StartPath As String = "", _
                         Optional FilterStr = "*.*|*.*", _
                         Optional Flag As Variant = &H8 Or &H200000) As String
  Dim Rc As Long
  Dim pOpenfilename As OPENFILENAME
  Dim Fstr1() As String
  Dim Fstr As String
  Dim I As Long
  Const MAX_Buffer_LENGTH = 256
 
  On Error Resume Next
 
  If Len(Trim$(StartPath)) > 0 Then
     If Right$(StartPath, 1) <> "\" Then StartPath = StartPath & "\"
   &

上一页  [1] [2] [3] [4]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台