弹来弹去跑马灯!

VB 获取所有窗体菜单信息

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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "?????"
   ClientHeight    =   7215
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   12180
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   7215
   ScaleWidth      =   12180
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1
      Height          =   1095
      Left            =   600
      MultiLine       =   -1  'True
      TabIndex        =   4
      Top             =   720
      Width           =   5535
   End
   Begin MSComctlLib.ListView ListView1
      Height          =   5055
      Left            =   120
      TabIndex        =   3
      Top             =   240
      Width           =   11655
      _ExtentX        =   20558
      _ExtentY        =   8916
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComDlg.CommonDialog CommonDialog1
      Left            =   3480
      Top             =   5520
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command2
      BackColor       =   &H00C0C0C0&
      Caption         =   "All"
      Height          =   615
      Left            =   8040
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   5640
      Width           =   1935
   End
   Begin VB.CommandButton Command1
      BackColor       =   &H00C0C0C0&
      Caption         =   "get menus from file(*.frm)"
      Height          =   735
      Left            =   5040
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   5640
      Width           =   2175
   End
   Begin VB.Label Label1
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "MADE BY ANJIAN"
      BeginProperty Font
         Name            =   "Tahoma"
         Size            =   14.25
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   285
      Left            =   120
      TabIndex        =   2
      Top             =   5700
      Width           =   2310
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const sFolder = "D:\projectVB6\Test"
Dim str As String
Dim strAll As String
 
Private Sub Command1_Click()
    On Error GoTo 1
    Dim sCaption As String
    sCaption = ""
    str = ""
    ListView1.ListItems.Clear
    Dim i As Integer
    Dim pos As Integer
    Dim count As Integer
    Dim spacelen As Integer
    Dim freenum As Integer
    freenum = FileSystem.FreeFile
    With CommonDialog1
        .Filter = "*.frm|*.frm"
        .FileName = ""
        .ShowOpen
        If Trim(.FileName) = "" Then
            Exit Sub
        End If
        Open .FileName For Input As freenum
        Do While Not EOF(freenum)
            i = i + 1
            Line Input #freenum, str
            pos = InStr(1, str, "Begin VB.Menu", vbTextCompare)    '?????
            If pos > 0 Then
                count = count + 1
                spacelen = ((pos - 1) \ 3 - 1) * 4
                ListView1.ListItems.Add , "name" & count, Space(spacelen) & Trim(Right(str, Len(str) - pos - 12))
                ListView1.ListItems.Item(count).ListSubItems.Add , "caption" & count, ""
                ListView1.ListItems.Item(count).ListSubItems.Add , "index" & count, ""
                ListView1.ListItems.Item(count).ListSubItems.Add , "Checked" & count, "False"
                ListView1.ListItems.Item(count).ListSubItems.Add , "Enabled" & count, "True"
                ListView1.ListItems.Item(count).ListSubItems.Add , "Visible" & count, "True"
            End If
 
            pos = InStr(1, str, "Caption", vbTextCompare)  '????
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("caption" & count).Text = Space(spacelen) & Replace(Trim(Right(str, Len(str) - pos - 16)), """", "")
                    sCaption = ListView1.ListItems.Item(count).ListSubItems("caption" & count).Text
                    sCaption = Replace(sCaption, "&", "")
                    If Trim(sCaption) <> "-" Then
                        Text1.Text = Text1 & sCaption & vbCrLf
                    End If
 
                End If
            End If
           GoTo lbEnd
             
            pos = InStr(1, str, "Index", vbTextCompare)    '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("index" & count).Text = Space(spacelen) & Trim(Right(str, Len(str) - pos - 16))
                End If
            End If
            pos = InStr(1, str, "Checked", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Checked" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                End If
            End If
            pos = InStr(1, str, "Enabled", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Enabled" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                End If
            End If
 
 
 
            pos = InStr(1, str, "Visible", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Visible" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                    'fliter visible false
                    If Trim(Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")) = "False" Then
                        'ListView1.ListItems.Item(count).ListSubItems("caption" & count).Text = ""
                    End If
                End If
            End If
 
lbEnd:
 
            If InStr(1, str, "Attribute VB_Name", vbTextCompare) > 0 Then
                Exit Do
            End If
        Loop
        Close freenum
    End With
 
    Exit Sub
1:
 
End Sub
 
 
Private Sub getMenu(ByVal sFileName As String)
      On Error GoTo 1
    Dim sCaption As String
    Dim sCap As String
    sCap = ""
    sCaption = ""
    str = ""
   ' strAll = strAll & sFileName & vbCrLf
    ListView1.ListItems.Clear
    Dim i As Integer
    Dim pos As Integer
    Dim count As Integer
    Dim spacelen As Integer
    Dim freenum As Integer
    freenum = FileSystem.FreeFile
        Open sFileName For Input As freenum
        Do While Not EOF(freenum)
            i = i + 1
            Line Input #freenum, str
            pos = InStr(1, str, "Begin VB.Menu", vbTextCompare)    '?????
            If pos > 0 Then
                count = count + 1
                spacelen = ((pos - 1) \ 3 - 1) * 4
                ListView1.ListItems.Add , "name" & count, Space(spacelen) & Trim(Right(str, Len(str) - pos - 12))
                ListView1.ListItems.Item(count).ListSubItems.Add , "caption" & count, ""
                ListView1.ListItems.Item(count).ListSubItems.Add , "index" & count, ""
                ListView1.ListItems.Item(count).ListSubItems.Add , "Checked" & count, "False"
                ListView1.ListItems.Item(count).ListSubItems.Add , "Enabled" & count, "True"
                ListView1.ListItems.Item(count).ListSubItems.Add , "Visible" & count, "True"
            End If
 
            pos = InStr(1, str, "Caption", vbTextCompare)  '????
            If pos > 0 Then
                If count > 0 Then
                   ' ListView1.ListItems.Item(count).ListSubItems("caption" & count).Text = Space(spacelen) & Replace(Trim(Right(str, Len(str) - pos - 16)), """", "")
                    sCap = Space(spacelen) & Replace(Trim(Right(str, Len(str) - pos - 16)), """", "")
                    sCap = Replace(sCap, "&", "")
                    If Trim(sCap) <> "-" Then
                        'Text1.Text = Text1 & sCaption & vbCrLf
                        sCaption = sCaption & sCap & vbCrLf
                    End If
 
                End If
            End If
           GoTo lbEnd
             
            pos = InStr(1, str, "Index", vbTextCompare)    '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("index" & count).Text = Space(spacelen) & Trim(Right(str, Len(str) - pos - 16))
                End If
            End If
            pos = InStr(1, str, "Checked", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Checked" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                End If
            End If
            pos = InStr(1, str, "Enabled", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Enabled" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                End If
            End If
 
 
 
            pos = InStr(1, str, "Visible", vbTextCompare)  '??
            If pos > 0 Then
                If count > 0 Then
                    ListView1.ListItems.Item(count).ListSubItems("Visible" & count).Text = Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")
                    'fliter visible false
                    If Trim(Replace(Trim(Right(str, Len(str) - pos - 21)), "'", "")) = "False" Then
                        'ListView1.ListItems.Item(count).ListSubItems("caption" & count).Text = ""
                    End If
                End If
            End If
 
lbEnd:
 
            If InStr(1, str, "Attribute VB_Name", vbTextCompare) > 0 Then
                Exit Do
            End If
        Loop
        Close freenum
         
         ' strAll = "****************************************************************" & vbCrLf & Replace(sFileName, "D:\Git working\Hytek\SWMM7\", "") & vbCrLf & strAll
         
      If Trim(sCaption) <> "" Then
            sCaption = "****************************************************************" & vbCrLf & Replace(sFileName, sFolder & "\", "") & vbCrLf & sCaption
        End If
         strAll = strAll & sCaption & vbCrLf
 
    Exit Sub
1:
MsgBox Err.Description
End Sub
 
 
 
Private Sub Command2_Click()
Dim cnt As Integer, i As Integer
Dim fso As Object
Dim folder As Object
Dim subfolder As Object
Dim file As Object
Set fso = CreateObject("scripting.filesystemobject")
 
Set folder = fso.getfolder(sFolder) ' get all files in folder
 
For Each file In folder.Files
  If (Right(file, 4) = ".frm") Then
       cnt = cnt + 1
   End If
Next
 
For Each file In folder.Files
 
  If (Right(file, 4) = ".frm") Then
         'MsgBox file
         getMenu (file)
         i = i + 1
         Caption = file & " done." & i & "/" & cnt
   End If
Next
Set file = fso.CreateTextFile("c:\MMMenu-All.txt", True)
file.Write strAll
file.Close
Set fso = Nothing
Set folder = Nothing
 
Text1.Text = strAll
 
 
 
End Sub
 
Private Sub Form_Load()
    With ListView1
        .View = lvwReport
        .ColumnHeaders.Add , "name", "name"
        .ColumnHeaders.Add , "caption", "caption"
        .ColumnHeaders.Add , "index", "index"
        .ColumnHeaders.Add , "Checked", "Checked"
        .ColumnHeaders.Add , "Enabled", "Enabled"
        .ColumnHeaders.Add , "Visible", "Visible"
    End With
    SaveSetting "VBMenus", "path", "filename", App.Path & "\" & App.EXEName
End Sub
'*************************************************************************
'*************************************************************************
Private Sub toword(ByVal rowcount As Integer, ByVal fieldscount As Integer)
    On Error Resume Next
    If rowcount > 0 Then
        Dim wdapp As Word.Application
        Dim wddoc As Word.Document
        Dim atable As Word.Table
        Dim i As Integer, j As Integer
        Set wdapp = New Word.Application
        Set wddoc = wdapp.Documents.Add
        With wdapp
            .Visible = True
            .Activate
            Set atable = .ActiveDocument.Tables.Add(.Selection.Range, rowcount + 1, fieldscount)
            For i = 1 To fieldscount
                atable.Cell(1, i).Range.InsertAfter ListView1.ColumnHeaders(i)
            Next i
 
            For i = 1 To rowcount
                atable.Cell(i + 1, 1).Range.InsertAfter ListView1.ListItems(i).Text
                atable.Cell(i + 1, 2).Range.InsertAfter ListView1.ListItems(i).ListSubItems(1).Text
                atable.Cell(i + 1, 3).Range.InsertAfter ListView1.ListItems(i).ListSubItems(2).Text
                atable.Cell(i + 1, 4).Range.InsertAfter ListView1.ListItems(i).ListSubItems(3).Text
                atable.Cell(i + 1, 5).Range.InsertAfter ListView1.ListItems(i).ListSubItems(4).Text
                atable.Cell(i + 1, 6).Range.InsertAfter ListView1.ListItems(i).ListSubItems(5).Text
            Next i
        End With
        '??word??
        Set atable = Nothing
        Set wdapp = Nothing
        Set wddoc = Nothing
    Else
        MsgBox "err", vbCritical
    End If
End Sub

  

posted @   wgscd  阅读(879)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示