明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: mayuezxl

如何用CommonDialog对话框选取多个文件

[复制链接]
发表于 2005-8-21 22:20:00 | 显示全部楼层
  1. Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
  2.     (pOpenfilename As OPENFILENAME) As Long
  3. Public Const OFN_PATHMUSTEXIST = &H800
  4. Public Const OFN_FILEMUSTEXIST = &H1000
  5. Public Const OFN_HIDEREADONLY = &H4 '隐蔽只读复选框
  6. Public Const OFN_ALLOWMULTISELECT = &H200
  7. Private Const OFN_EXPLORER As Long = &H80000
  8. Public Type OPENFILENAME
  9.     lStructSize As Long
  10.     hwndOwner As Long '拥有对话框的窗口
  11.     hInstance As Long
  12.     lpstrFilter As String '装载文件过滤器的缓冲区
  13.     lpstrCustomFilter As String
  14.     nMaxCustFilter As Long
  15.     nFilterIndex As Long
  16.     lpstrFile As String
  17.     nMaxFile As Long
  18.     lpstrFileTitle As String
  19.     nMaxFileTitle As Long
  20.     lpstrInitialDir As String
  21.     lpstrTitle As String '对话框的标题
  22.     flags As Long
  23.     nFileOffset As Integer
  24.     nFileExtension As Integer
  25.     lpstrDefExt As String
  26.     lCustData As Long
  27.     lpfnHook As Long
  28.     lpTemplateName As String
  29. End Type
  30. '选择文件函数GetFile
  31. Function GetFile(strTitle As String, strFilter As String, Optional MultiSelect As Boolean = False, Optional strIniDir As String) As String
  32. On Error Resume Next
  33. Dim FileName As String
  34. Dim OFileBox As OPENFILENAME
  35. With OFileBox
  36.     .lpstrTitle = strTitle '对话框标题
  37.     .lpstrInitialDir = strIniDir '初始目录
  38.     .lStructSize = Len(OFileBox)
  39.     .hwndOwner = ThisDrawing.HWND
  40.     If MultiSelect Then
  41.         .flags = OFN_EXPLORER Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or OFN_ALLOWMULTISELECT
  42.     Else
  43.         .flags = OFN_EXPLORER Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
  44.     End If
  45.     .lpstrFile = String$(255, 0)
  46.     .nMaxFile = 255
  47.     .lpstrFileTitle = String$(255, 0)
  48.     .nMaxFileTitle = 255
  49.     .lpstrFilter = strFilter  '过滤器
  50.     .nFilterIndex = 1
  51. End With
  52. lntFile = GetOpenFileName(OFileBox) '执行打开对话框
  53. If lntFile <> 0 Then
  54.         FileName = Left(OFileBox.lpstrFile, InStr(OFileBox.nFileOffset + 1, OFileBox.lpstrFile, _
  55.                         Chr(0) & Chr(0), vbBinaryCompare))
  56.     GetFile = FileName
  57. Else
  58.     GetFile = ""
  59. End If
  60. End Function
  61. '示例
  62. Sub gf()
  63.     Dim f As String
  64.     f = GetFile("明经通道 http://www.mjtd.com VBA 示例", "图形文件(*.dwg)" & vbNullChar & "*.dwg", True)
  65.     Debug.Print f
  66. End Sub

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 10:26 , Processed in 0.147420 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表