-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodCommonDialog.bas
More file actions
172 lines (147 loc) · 4.72 KB
/
modCommonDialog.bas
File metadata and controls
172 lines (147 loc) · 4.72 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Attribute VB_Name = "modCommonDialog"
Option Explicit
' zunächst die benötigten API-Deklarationen
Private 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
Private Const OFN_READONLY = &H1
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHOWHELP = &H10
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOLONGNAMES = &H40000
Private Const OFN_EXPLORER = &H80000
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_LONGNAMES = &H200000
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHAREWARN = 0
Private Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" ( _
pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" ( _
pOpenfilename As OPENFILENAME) As Long
' Öffnen-Dialog
Public Function ShowOpenDlg(F As Form, strFilter As String, _
strTitel As String, strInitDir As String) As String
Dim lngOpenFileName As OPENFILENAME
Dim lngAnt As Long
With lngOpenFileName
.lStructSize = Len(lngOpenFileName)
.hwndOwner = F.hWnd
.hInstance = App.hInstance
If Right$(strFilter, 1) <> "|" Then _
strFilter = strFilter + "|"
For lngAnt = 1 To Len(strFilter)
If Mid$(strFilter, lngAnt, 1) = "|" Then _
Mid$(strFilter, lngAnt, 1) = Chr$(0)
Next
.lpstrFilter = strFilter
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = strInitDir
.lpstrTitle = strTitel
.flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
lngAnt = GetOpenFileName(lngOpenFileName)
If (lngAnt) Then
ShowOpenDlg = Trim$(.lpstrFile)
Else
ShowOpenDlg = ""
End If
End With
End Function
' Speichern-Dialog
Public Function ShowSaveDlg(F As Form, strFilter As String, _
strTitel As String, strInitDir As String) As String
Dim lngOpenFileName As OPENFILENAME
Dim lngAnt As Long
With lngOpenFileName
.lStructSize = Len(lngOpenFileName)
.hwndOwner = F.hWnd
.hInstance = App.hInstance
If Right$(strFilter, 1) <> "|" Then _
strFilter = strFilter + "|"
For lngAnt = 1 To Len(strFilter)
If Mid$(strFilter, lngAnt, 1) = "|" Then _
Mid$(strFilter, lngAnt, 1) = Chr$(0)
Next
.lpstrFilter = strFilter
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = strInitDir
.lpstrTitle = strTitel
.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or _
OFN_CREATEPROMPT
lngAnt = GetSaveFileName(lngOpenFileName)
If (lngAnt) Then
ShowSaveDlg = Trim$(.lpstrFile)
Else
ShowSaveDlg = ""
End If
End With
End Function
Public Function FileExists(ByVal sFile As String) As Boolean
' Der Parameter sFile enthält den zu prüfenden Dateinamen
Dim Size As Long
On Local Error Resume Next
Size = FileLen(sFile)
FileExists = (Err = 0)
On Local Error GoTo 0
End Function
' Beliebige Datei auslesen und
' Inhalt als String zurückgeben
Public Function ReadFile(ByVal sFilename As String) _
As String
Dim F As Integer
Dim sInhalt As String
' Prüfen, ob Datei existiert
If Dir$(sFilename, vbNormal) <> "" Then
' Datei im Binärmodus öffnen
F = FreeFile: Open sFilename For Binary As #F
' Größe ermitteln und Variable entsprechend
' mit Leerzeichen füllen
sInhalt = Space$(LOF(F))
' Gesamten Inhalt in einem "Rutsch" einlesen
Get #F, , sInhalt
' Datei schliessen
Close #F
End If
ReadFile = sInhalt
End Function