-
Notifications
You must be signed in to change notification settings - Fork 3
/
General.bas
284 lines (242 loc) · 9.2 KB
/
General.bas
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
Attribute VB_Name = "General"
Option Explicit
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 Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Const MAX_PATH = 260
Private Const WM_USER = &H400
Private Const OFN_EXPLORER = &H80000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const BIF_RETURNONLYFSDIRS = &H1
Private Const BIF_DONTGOBELOWDOMAIN = &H2
Private Const BIF_NEWDIALOGSTYLE As Long = &H40
Private Const BFFM_INITIALIZED = &H1
Private Const BFFM_SETSELECTIONA = (WM_USER + 102)
Private Const cSingleSelFlags As Long = OFN_EXPLORER Or OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST Or OFN_OVERWRITEPROMPT
Public Declare Function SHGetIDListFromPath Lib "Shell32" Alias "#162" (ByVal pszPath As String) As Long
Private Declare Function SHGetFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ppidl As Long) As Long
Private Declare Function lstrcat Lib "kernel32.dll" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public NoUsarCabecera As Boolean
Public TilePixelHeight As Integer
Public TilePixelWidth As Integer
Public IniPath As String
Public GraphicsFile As String
Public IniPathD As String
Public GraphicsFileD As String
Public DirGraphics As String
Public Const SW_NORMAL = 1
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub Main()
TilePixelHeight = 32
TilePixelWidth = 32
DIU.Show
' modo de uso
' dindex c:/ao/init/graficos.ind -> desindexa
' dindex c:/ao/init/graficos.ind.txt -i -> indexa
'Dim command As String
'command = Chr(34) & "D:\AO\Des-Indexador 0.13.0\Graficos3.ind" & Chr(34)
'command = Right(Left(command, Len(command) - 1), Len(command) - 2)
'IniPath = ParsePath(command, vbDirectory)
'GraphicsFile = ParsePath(command, vbArchive)
'MsgBox LoadGrhData
'MsgBox "okay"
End Sub
Public Function GuardarDesindex() As Boolean
On Error Resume Next
Dim OFName As OPENFILENAME
Dim sT As String
GuardarDesindex = False
On Local Error Resume Next
With OFName
.lStructSize = Len(OFName)
.hWndOwner = DIU.hWnd
.hInstance = App.hInstance
.lpstrFilter = "Indices desindexados (*.ini)" & Chr$(0) & "*.ini" & Chr$(0) & "Todos los archivos" & Chr$(0) & "*.*"
.lpstrTitle = "Guardar el Indice Desindexado"
.Flags = cSingleSelFlags
.lpstrFile = Space$(1023)
.nMaxFile = 1024
End With
If Not GetSaveFileName(OFName) = 0 Then
sT = Split(Trim$(OFName.lpstrFile), Chr(0))(0)
If LCase$(Right$(sT, 4)) <> ".ini" Then sT = sT & ".ini"
IniPathD = ParsePath(sT, vbDirectory)
GraphicsFileD = ParsePath(sT, vbArchive)
GuardarDesindex = True
Else
Exit Function
End If
End Function
Public Function GuardarIndex() As Boolean
On Error Resume Next
Dim OFName As OPENFILENAME
Dim sT As String
GuardarIndex = False
On Local Error Resume Next
With OFName
.lStructSize = Len(OFName)
.hWndOwner = DIU.hWnd
.hInstance = App.hInstance
.lpstrFilter = "Indices (*.ind)" & Chr$(0) & "*.ind" & Chr$(0) & "Todos los archivos" & Chr$(0) & "*.*"
.lpstrTitle = "Guardar el Indice Indexado"
.Flags = cSingleSelFlags
.lpstrFile = Space$(1023)
.nMaxFile = 1024
End With
If Not GetSaveFileName(OFName) = 0 Then
sT = Split(Trim$(OFName.lpstrFile), Chr(0))(0)
If LCase$(Right$(sT, 4)) <> ".ind" Then sT = sT & ".ind"
IniPathD = ParsePath(sT, vbDirectory)
GraphicsFileD = ParsePath(sT, vbArchive)
GuardarIndex = True
Else
Exit Function
End If
End Function
Public Function ExplorarIndex() As Boolean
On Error Resume Next
Dim OFName As OPENFILENAME
Dim sT As String
ExplorarIndex = False
On Local Error Resume Next
With OFName
.lStructSize = Len(OFName)
.hWndOwner = DIU.hWnd
.hInstance = App.hInstance
.lpstrFilter = "Indices desindexados (*.ini)" & Chr$(0) & "*.ini" & Chr$(0) & "Todos los archivos" & Chr$(0) & "*.*"
.lpstrTitle = "Seleccione un Indice para Indexar"
.Flags = cSingleSelFlags
.lpstrFile = Space$(1023)
.nMaxFile = 1024
End With
If Not GetOpenFileName(OFName) = 0 Then
sT = Split(Trim$(OFName.lpstrFile), Chr(0))(0)
IniPath = ParsePath(sT, vbDirectory)
GraphicsFile = ParsePath(sT, vbArchive)
ExplorarIndex = True
Else
Exit Function
End If
End Function
Public Function ExplorarDesindex() As Boolean
On Error Resume Next
Dim OFName As OPENFILENAME
Dim sT As String
ExplorarDesindex = False
On Local Error Resume Next
With OFName
.lStructSize = Len(OFName)
.hWndOwner = DIU.hWnd
.hInstance = App.hInstance
.lpstrFilter = "Indices (*.ind)" & Chr$(0) & "*.ind" & Chr$(0) & "Todos los archivos" & Chr$(0) & "*.*"
.lpstrTitle = "Seleccione un Indice para Desindexar"
.Flags = cSingleSelFlags
.lpstrFile = Space$(1023)
.nMaxFile = 1024
End With
If Not GetOpenFileName(OFName) = 0 Then
sT = Split(Trim$(OFName.lpstrFile), Chr(0))(0)
IniPath = ParsePath(sT, vbDirectory)
GraphicsFile = ParsePath(sT, vbArchive)
ExplorarDesindex = True
Else
Exit Function
End If
End Function
Public Function ParsePath(strFullPathName As String, ReturnType As Byte) As String
Dim strTemp As String, intX As Integer, strPathName As String, strFileName As String
If Len(strFullPathName) > 0 Then
strTemp = ""
intX = Len(strFullPathName)
Do While strTemp <> "\"
strTemp = mid(strFullPathName, intX, 1)
If strTemp = "\" Then
strPathName = Left(strFullPathName, intX)
strFileName = Right(strFullPathName, Len(strFullPathName) - intX)
End If
intX = intX - 1
Loop
Select Case ReturnType
Case vbDirectory
ParsePath = strPathName
Case vbArchive
ParsePath = strFileName
Case Else
ParsePath = strFullPathName
End Select
Else
ParsePath = ""
End If
End Function
Public Function SelDirGraficos(Optional ByVal Mensaje As String = "Seleccione el Directorio en donde se encuentran los Graficos...") As Boolean
Dim lpIDList As Long
Dim sBuffer As String
Dim tBrowseInfo As BrowseInfo
DirGraphics = ""
lpIDList = SHGetFolderLocation(DIU.hWnd, 6, SHGetIDListFromPath(App.Path), 0, tBrowseInfo.pIDLRoot)
With tBrowseInfo
.hWndOwner = DIU.hWnd
.lpfnCallback = adr(AddressOf BrowseCallbackProc)
.lpszTitle = lstrcat(Mensaje, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_NEWDIALOGSTYLE
.lParam = SHGetIDListFromPath(StrConv(App.Path, vbUnicode))
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
DirGraphics = sBuffer & "\"
SelDirGraficos = True
Else
SelDirGraficos = False
End If
End Function
Function adr(n As Long) As Long
adr = n
End Function
Public Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
If uMsg = BFFM_INITIALIZED Then
Call SendMessage(hWnd, BFFM_SETSELECTIONA, False, ByVal lpData)
End If
End Function
Public Function FileExist(ByVal file As String, ByVal FileType As VbFileAttribute) As Boolean
FileExist = (Dir$(file, FileType) <> "")
End Function