-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMainHelper.bas
More file actions
544 lines (389 loc) · 15.1 KB
/
MainHelper.bas
File metadata and controls
544 lines (389 loc) · 15.1 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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
Attribute VB_Name = "MainHelper"
Option Explicit
Public Layout As LayoutParser
Public g_winLoading As frmAbout
Public Settings As ViSettings
Public CmdLine As CommandLine
Public MetroUtility As Windows8Utility
Public IconManager As CIconManager
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" _
(iccex As tagInitCommonControlsEx) As Boolean
Private Const ICC_USEREX_CLASSES = &H200
Private sOldIconSize As String
Private m_IgnorePreviousInstance As Boolean
Public g_Exiting As Boolean
Public g_rolloverImage As GDIPImage
Public g_viOrb_fullHeight As Boolean
Public g_WDSInitialized As Boolean
Public g_resourcesPath As String
Public g_rolloverPath As String
Public g_startButtonFindAttempts As Long
Private m_initializedGlobalClasses As Boolean
Private Const EXIT_PROGRAM As Long = 1
Private m_logger As SeverityLogger
Private Property Get Logger() As SeverityLogger
If m_logger Is Nothing Then
Set m_logger = LogManager.GetLogger("MainHelper")
End If
Set Logger = m_logger
End Property
Public Function WaitForDesktop()
ShellHelper.UpdateHwnds
While IsWindow(ShellHelper.g_lnghwndTaskBar) = APIFALSE Or IsWindowVisible(ShellHelper.g_lnghwndTaskBar) = APIFALSE
ShellHelper.UpdateHwnds
Sleep 500
Wend
End Function
Public Function GetResourceBitmap(ByVal theName) As IPictureDisp
On Error GoTo Handler
If FileExists(ResourcesPath & CStr(theName) & ".bmp") Then
Set GetResourceBitmap = LoadPicture(ResourcesPath & CStr(theName) & ".bmp")
Else
Set GetResourceBitmap = LoadResPicture(theName, vbResBitmap)
End If
Handler:
End Function
Public Function GetProgramMenuBackColour() As Long
On Error GoTo Handler
GetProgramMenuBackColour = vbWhite
Dim xmlLayout As New DOMDocument
Dim subElement As IXMLDOMElement
If xmlLayout.Load(ResourcesPath & "layout.xml") = False Then
GetProgramMenuBackColour = vbWhite
Exit Function
End If
Set subElement = xmlLayout.selectSingleNode("startmenu_base//vielement[@id='programmenu']")
GetProgramMenuBackColour = HEXCOL2RGB(getAttribute_IgnoreError(subElement, "backcolour", "#ffffff"))
Exit Function
Handler:
End Function
Public Function FileCheck(szSourcePath As String) As Boolean
If Not FileExists(szSourcePath & "startmenu.png") Or _
Not FileExists(szSourcePath & "userframe.png") Or _
Not FileExists(szSourcePath & "bottombuttons_arrow.png") Or _
Not FileExists(szSourcePath & "bottombuttons_shutdown.png") Or _
Not FileExists(szSourcePath & "allprograms.png") Or _
Not FileExists(szSourcePath & "button.png") Or _
Not FileExists(szSourcePath & "programs_arrow.png") Then
FileCheck = False: Exit Function
End If
FileCheck = True
End Function
Public Function InitCommonControlsVB() As Boolean
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
' Ensure CC available:
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error GoTo 0
End Function
Function InitClasses_IfNeeded() As Boolean
If m_initializedGlobalClasses Then
InitClasses_IfNeeded = True
Exit Function
End If
m_initializedGlobalClasses = True
InitCommonControlsVB
Set Layout = New LayoutParser
Set MetroUtility = New Windows8Utility
Set IconManager = New CIconManager
If Not Layout.ParseStartMenu(ResourcesPath & "layout.xml").ErrorCode = 0 Then
Exit Function
End If
SetOpenSaveDocs
g_viOrb_fullHeight = Layout.ViOrb_FullHeight
InitClasses_IfNeeded = True
End Function
Function TermForms()
Set frmEvents = Nothing
End Function
Function InitForms()
Load frmVistaMenu
Load frmEvents
frmEvents.Test
End Function
Function ShowLoadingForm()
Set g_winLoading = New frmAbout
With g_winLoading
.Caption = ""
.Label3.fontSize = 9
.Label2.fontSize = 9
.Label1.fontSize = 9
.cmdUpdate.Visible = False
.CmdOK.Visible = False
'.lblLink.Visible = False
.lblLink.Top = 100 * Screen.TwipsPerPixelY
.lblLink.Left = 90 * Screen.TwipsPerPixelX
.Label5.Visible = False
.Label6.Visible = False
.Label4.Visible = False
.lblBottom.Caption = ""
.lblBottom.Top = 85 * Screen.TwipsPerPixelY
.lblBottom.Width = 263 * Screen.TwipsPerPixelX
.lblEmail.Caption = ""
.lblEmail.Top = 133 * Screen.TwipsPerPixelY
.lblEmail.FontBold = True
.timUpdate.Enabled = True
.Height = 125 * Screen.TwipsPerPixelY
.Width = 266 * Screen.TwipsPerPixelX
.Show
End With
End Function
Function SetLoadingCaption(strCaption)
With g_winLoading
.lblBottom.Caption = strCaption
End With
End Function
Sub MakeUserRollover(szResourcesPath As String)
Dim BITMAP As New GDIPBitmap
Dim BitmapGraphics As New GDIPGraphics
Dim UserPic As New GDIPImage
Dim UserFrame As New GDIPImage
Dim encoder As New GDIPImageEncoderList
Dim sBmpUserPath As String
Dim ProgramDataPath As String
Dim thisCLSID As CLSID
Dim theImageFace As New GDIPImage
Dim shellFoldersRegKey As RegistryKey
Set shellFoldersRegKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
If shellFoldersRegKey Is Nothing Then
Logger.Error "Unable to create User rollover, couldn't open registry key", "MakeUserRollover"
Exit Sub
End If
ProgramDataPath = shellFoldersRegKey.GetValue("Common AppData")
sBmpUserPath = ProgramDataPath & "\Microsoft\User Account Pictures\" & Environ$("USERNAME") & ".bmp"
If FileExists(sBmpUserPath) = False Then
'sBmpUserPath = ProgramDataPath & "\Microsoft\User Account Pictures\user.bmp"
sBmpUserPath = Environ$("TEMP") & "\" & Environ$("USERNAME") & ".bmp"
If FileExists(GetUserTilePath) Then
sBmpUserPath = GetUserTilePath()
End If
If FileExists(sBmpUserPath) = False Then
If FileExists(Environ$("programdata") & "\Microsoft\User Account Pictures\user.png") Then
sBmpUserPath = Environ$("programdata") & "\Microsoft\User Account Pictures\user.png"
ElseIf FileExists(Environ$("programdata") & "\Microsoft\User Account Pictures\guest.bmp") Then
sBmpUserPath = Environ$("programdata") & "\Microsoft\User Account Pictures\guest.bmp"
ElseIf FileExists(ProgramDataPath & "\Microsoft\User Account Pictures\Guest.bmp") Then
sBmpUserPath = ProgramDataPath & "\Microsoft\User Account Pictures\Guest.bmp"
End If
End If
End If
If FileExists(sBmpUserPath) = False Or _
FileExists(szResourcesPath & "userframe.png") = False Then
Exit Sub
End If
UserPic.FromFile sBmpUserPath
UserFrame.FromFile szResourcesPath & "userframe.png"
BITMAP.CreateFromSizeFormat UserFrame.Width, UserFrame.Height, PixelFormat.Format32bppArgb
BitmapGraphics.FromImage BITMAP.Image
BitmapGraphics.DrawImage UserPic, 11, 11, 48, 48
BitmapGraphics.DrawImage UserFrame, 0, 0, UserFrame.Width, UserFrame.Height
Set MainHelper.g_rolloverImage = BITMAP.Image.Clone
End Sub
Sub InitRecentPrograms()
Dim defaultFont As ViFont
Dim m_recentPrograms As frmFreq
Set defaultFont = New ViFont
Set m_recentPrograms = New frmFreq
defaultFont.Size = 9
defaultFont.Colour = vbBlack
defaultFont.Face = g_DefaultFont.FontFace
m_recentPrograms.TrueFont = defaultFont
m_recentPrograms.BackColor = CLng(Layout.FrequentProgramsMenuColour)
m_recentPrograms.Show
End Sub
Private Function HandleWindows8Utility() As Long
HandleWindows8Utility = EXIT_PROGRAM
DetermineWindowsVersion_IfNeeded
If g_Windows8 Or g_Windows81 Then
Set MetroUtility = New Windows8Utility
MetroUtility.ActionSettings
End If
WaitUntilDesktopIsAvailable
Exit Function
Handler:
Logger.Error Err.Description, "HandleWindows8Utility"
End Function
Function DetermineProgramAction() As Long
Dim newThemeName As String
Dim newOrbName As String
Dim cmdLineArguements() As String
If CmdLine Is Nothing Then
Set CmdLine = New CommandLine
End If
If CmdLine.arguments > 0 Then
Select Case LCase$(CmdLine.Argument(1))
'Case "/show"
Case "/ignorepreviousinstance"
m_IgnorePreviousInstance = True
Case "/debug":
sVar_bDebugMode = True
LogManager.Target = LogAll
LogManager.MinimumLevel = TraceLevel
Case "/nuke_metro"
DetermineProgramAction = HandleWindows8Utility()
Case "/install_orb"
SetVars_IfNeeded
SetDefaultFont_IfNeeded
If CmdLine.arguments > 1 Then
If Not InstallOrb(CmdLine.Argument(2), newOrbName) Then
ExitApplication
Exit Function
End If
If FindWindow(vbNullString, MASTERID) <> 0 Then
DetermineProgramAction = EXIT_PROGRAM
SendAppMessage 0, FindWindow(vbNullString, MASTERID), "NEW_ORB " & URLEncode(newOrbName)
ExitApplication
Exit Function
Else
Set Settings = New ViSettings
Settings.CurrentOrb = newOrbName
End If
End If
Case "/install_theme"
SetVars_IfNeeded
SetDefaultFont_IfNeeded
If CmdLine.arguments > 1 Then
If Not InstallTheme(CmdLine.Argument(2), newThemeName) Then
ExitApplication
Exit Function
End If
If FindWindow(vbNullString, MASTERID) <> 0 Then
DetermineProgramAction = EXIT_PROGRAM
SendAppMessage 0, FindWindow(vbNullString, MASTERID), "NEW_THEME " & URLEncode(newThemeName)
ExitApplication
Exit Function
Else
Set Settings = New ViSettings
Settings.CurrentSkin = newThemeName
End If
End If
Case "/pin"
SetVars_IfNeeded
SetDefaultFont_IfNeeded
If CmdLine.arguments > 1 Then
If FindWindow(vbNullString, MASTERID) <> 0 Then
DetermineProgramAction = EXIT_PROGRAM
SendAppMessage 0, FindWindow(vbNullString, MASTERID), "PIN_FILE " & URLEncode(CmdLine.Argument(2))
ExitApplication
Exit Function
End If
End If
End Select
End If
End Function
Sub Main()
LogManager.MinimumLevel = ErrorLevel
LogManager.Target = LogDebug
If Not InitClasses_IfNeeded Then
Exit Sub
End If
If DetermineProgramAction = EXIT_PROGRAM Then
ExitApplication
Exit Sub
End If
If Not m_IgnorePreviousInstance And _
FindWindow(vbNullString, MASTERID) <> 0 Then
ExitApplication
Exit Sub
End If
SetVars_IfNeeded
SetDefaultFont_IfNeeded
DetermineWindowsVersion_IfNeeded
InitializeGDIIfNotInitialized
g_WDSInitialized = WDSAvailable
If Settings Is Nothing Then Set Settings = New ViSettings
If Settings.CurrentSkin <> vbNullString Then
g_resourcesPath = sCon_AppDataPath & "_skins\" & Settings.CurrentSkin & "\"
End If
If Settings.CurrentRollover <> vbNullString Then
g_rolloverPath = sCon_AppDataPath & "_rollover\" & Settings.CurrentRollover & "\"
Else
g_rolloverPath = sCon_AppDataPath & "_skins\" & Settings.CurrentSkin & "\rollover\"
End If
If ValidateOptions = False Then
End
End If
If Not FileCheck(ResourcesPath) Then
MessageBox 0, "Unable to locate resources!", "File check failed!", MB_ICONEXCLAMATION
AppLauncherHelper.ShellEx "http://www.lee-soft.com/vistart/"
Exit Sub
End If
'testComponent
'Exit Sub
WaitForDesktop
App.TaskVisible = False
'We need this
Set g_colSearch = New Collection
ProgramIndexingHelper.Initialize
MakeUserRollover ResourcesPath
NTEnableShutDown ""
If App.CompanyName <> "Lee-Soft.com" Then
End
End If
g_sVar_Layout_BackColour = GetProgramMenuBackColour()
'If Not g_Windows8 Then
While IsWindow(ShellHelper.g_lnghwndTaskBar) = APIFALSE And g_startButtonFindAttempts < 10
g_startButtonFindAttempts = g_startButtonFindAttempts + 1
Sleep 1000
ShellHelper.UpdateHwnds
DoEvents
Wend
'Else
If IsWindow(ShellHelper.g_hwndStartButton) = APIFALSE Then
If IsWindow(ShellHelper.g_lngHwndViOrbToolbar) = APIFALSE Then
If g_Windows8 And Not g_Windows81 Then frmInstall.Show vbModal
End If
End If
If Settings.ShowSplashScreen = True Then
ShowLoadingForm
SetLoadingCaption "LOADING"
End If
DoEvents
InitForms
If Settings.ShowSplashScreen = True Then
g_winLoading.timSplashMin.Enabled = True
End If
If Not g_WDSInitialized Then Index_MyDirectory
If App.CompanyName <> "Lee-Soft.com" Then
End
End If
CreateFileAssociation ".vistart-theme", "VistartTheme", "A ViStart Theme Package", App.Path & "\" & App.EXEName & ".exe"
'Exit Sub
RegisterAppRestart
End Sub
Function GetSystemLargeIconSize() As Integer
Dim strTemp As String
On Error GoTo Handler
Dim windowMetricsRegKey As RegistryKey
Set windowMetricsRegKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop\WindowMetrics")
'Get this system's Icon size
strTemp = windowMetricsRegKey.GetValue("Shell Icon Size", "32")
GetSystemLargeIconSize = CInt(strTemp)
Exit Function
Handler:
Logger.Warn "Could not open registry key, IconSize 32 will be assumed", "GetSystemLargeIconSize"
GetSystemLargeIconSize = 32
End Function
Sub ExitApplication()
If g_Exiting Then Exit Sub
On Error Resume Next
g_Exiting = True
PutOptions
Unload frmEvents
While Forms.count > 0
Dim F As Form
For Each F In Forms
Unload F
Next
Wend
DoEvents
End Sub