|
CommonDialog
#33642271
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
Участник
Откуда: Moscow
Сообщения: 2 001
|
|
вот это попробуйте:
На кнопке:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25.
Dim strFile As String
Dim strFilter As String
On Error GoTo Err_cmdOpen_Click
' Узнать у пользователя путь к файлу
strFilter = "Все поддерживаемые файлы(*.adtg,*.rar)|*.adtg;*.rar|" _
& "ADTG-формат (*.adtg)|*.adtg|" _
& "RAR-архив (*.rar)|*.rar||"
strFile = Get_File_Name(Me.hWnd, "Открыть файл...", CurrentProject.Path, strFilter)
If Len(strFile) > 0 Then
If Right$(strFile, 4 ) = ".rar" Or Right$(strFile, 5 ) = ".adtg" Then
... обработка файла
Else
MsgBox "Извините, поддерживаются только форматы ADTG и RAR!", vbExclamation, "Неизвестный формат"
End If
End If
Exit_cmdOpen_Click:
Exit Sub
Err_cmdOpen_Click:
ufErrorNotification "cmdOpen_Click"
Resume Exit_cmdOpen_Click
В модуле:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134.
Option Compare Database
Option Explicit
Type OPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer
Public Const OFN_READONLY = &H1
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_SHOWHELP = &H10
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOLONGNAMES = &H40000
Public Const OFN_EXPLORER = &H80000 'new look commdlg
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_LONGNAMES = &H200000 'force long names for 3.x modules
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
Public Function Get_File_Name(hWnd As Long, _
title As String, _
Path As String, _
txt_filter As String) As String
Get_File_Name = Get_File_NameCommon(hWnd, title, Path, "", "", txt_filter, True)
End Function
Public Function Get_File_NameCommon(hWnd As Long, _
title As String, _
Path As String, _
Ftitle As String, _
fext As String, _
txt_filter As String, _
saveflag As Boolean) As String
Dim ofn As OPENFILENAME
Dim ret As Long
Dim fn As String * 129 , fp As String * 129
Dim s As String, i As Integer
' On Error GoTo errfnm
Get_File_NameCommon = ""
txt_filter = Replace(txt_filter, "|", Chr( 0 ))
If Len(Ftitle) <> 0 Then fn = Ftitle + Chr( 0 )
With ofn
.lStructSize = 76
.hWndOwner = hWnd
'ofn.hInstance = 0
.lpstrFilter = txt_filter
.lpstrCustomFilter = 0
.nMaxCustFilter = 0
.nFilterIndex = 1
.lpstrFile = fn
.nMaxFile = 128
.lpstrFileTitle = fp
.nMaxFileTitle = 128
.lpstrInitialDir = Path
.lpstrTitle = title
End With
If Len(fext) <> 0 Then ofn.lpstrDefExt = fext
If Not saveflag Then
ofn.flags = OFN_PATHMUSTEXIST + _
OFN_FILEMUSTEXIST + _
OFN_NOLONGNAMES + _
OFN_EXPLORER + 0
ret = GetOpenFileName(ofn)
Else
ofn.flags = OFN_PATHMUSTEXIST + _
OFN_NOLONGNAMES + _
OFN_EXPLORER + 0
ret = GetSaveFileName(ofn)
End If
'ofn.nFileOffset = 0
'ofn.nFileExtension = 0
'ofn.lCustData = 0
'ofn.lpfnHook = 0
'ofn.lpTemplateName = 0
Get_File_NameCommon = ""
If ret <> 0 Then
For i = 1 To 129
s = Mid$(ofn.lpstrFile, i, 1 )
If Asc(s) = 0 Or Len(s) = 0 Then Exit For
Get_File_NameCommon = Get_File_NameCommon & s
Next
End If
exitfnm:
Exit Function
errfnm:
MsgBox Err.Description
Get_File_NameCommon = ""
Resume exitfnm
End Function
|
|
|