forked from lee-soft/ViStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartBarSupport.bas
928 lines (679 loc) · 28.1 KB
/
StartBarSupport.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
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
Attribute VB_Name = "StartBarSupport"
Public Const MAX_PATH As Long = 260
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Enum PowerMenuCommands
ShowOptions = 1
ShowAbout = 2
LogOff = 3
PowerOff = 4
Reboot = 5
Hibernate = 6
StandBy = 7
End Enum
Private Type StartOption
Caption As String
Shell As String
Exists As Boolean
ContextMenu As ContextMenu
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Type rolloverImage
Rollover As String
Exists As Boolean
End Type
Public g_bStartMenuVisible As Boolean
Public win_txtSearch As Long
Public StartOptions() As StartOption
Public sVar_bDebugMode As Boolean
Public sVar_sFontName As String
Public sVar_Reg_StartMenu_MyDocuments As String
Public sVar_Reg_StartMenu_CommonUser As String
Public sVar_Reg_StartMenu_CurrentUser As String
Public sVar_Reg_StartMenu_CommonPrograms As String
Public sVar_Reg_StartMenu_CurrentUserPrograms As String
Public sVar_Reg_StartMenu_CurrentUserRecentItems As String
Public sVar_Reg_Desktop As String
Public g_sVar_Layout_BackColour As Long
Public iLastFileCount(0 To 3) As Long
Public iLastFolderCount(0 To 3) As Long
Public fFolder_Monitor(0 To 3) As Scripting.Folder
Public rRealStartBarPosition As RECT
'Public ProgramDB As New clsProgramDB
Public Const sCon_Reg_AppPath As String = "Software\ViStart\"
Public sCon_AppDataPath As String
Public sCon_OrbFolderPath As String
Public FSO As New FileSystemObject
Private m_optionsPopulated As Boolean
Public g_DefaultFont As GDIFont
Public g_DefaultFontItalic As GDIFont
Public g_KeyboardMenuState As Long
Public g_KeyboardSide As Long
Public AppPath As String
Dim bHasRecentItems As Boolean
Private m_logger As SeverityLogger
Private Property Get Logger() As SeverityLogger
If m_logger Is Nothing Then
Set m_logger = LogManager.GetLogger("StartBarSupport")
End If
Set Logger = m_logger
End Property
Public Function PopulateUserStringsFromXML(ByVal szSourceFile As String)
Dim xmlLanguageFile As New DOMDocument
'Defaults
UserVariable.Add "Log Off", "strLogOff"
UserVariable.Add "Switch User", "strSwitchUser"
UserVariable.Add "Shutdown", "strShutdown"
UserVariable.Add "Restart", "strRestart"
UserVariable.Add "Stand By", "strStandBy"
UserVariable.Add "Hibernate", "strHibernate"
UserVariable.Add "Exit", "strExit"
UserVariable.Add "About", "strAbout"
UserVariable.Add "Options", "strOptions"
UserVariable.Add "All Programs", "strAllPrograms"
UserVariable.Add "Back", "strBack"
UserVariable.Add "No programs match the search criteria", "strNotFound"
UserVariable.Add "See all results", "strSeeAllResults"
UserVariable.Add "Start Search", "strStartSearch"
UserVariable.Add "Program Options", "strProgramOptions"
UserVariable.Add "Enable Auto-Click feature", "strEnableAutoClick"
UserVariable.Add "Show ViStart's Tray Icon", "strShowTrayIcon"
UserVariable.Add "Start with Windows", "strStartWithWindows"
UserVariable.Add "Show splash screen on startup", "strSplash"
UserVariable.Add "Clear frequently used program list", "strClearFrequentList"
UserVariable.Add "Indexing Options", "strIndexOptions"
UserVariable.Add "Invoke ViStart with Windows Key", "strFilterWinKey"
UserVariable.Add "Pick a new Start Menu Skin...", "strNewSkin"
UserVariable.Add "Pick a new Start Button image...", "strOrbNew"
UserVariable.Add "Reset Orb image", "strOrbReset"
UserVariable.Add "Run...", "strRun"
UserVariable.Add "Sleep...", "strSleep"
UserVariable.Add "OK", "strOK"
UserVariable.Add "Cancel", "strCancel"
UserVariable.Add "Browse", "strBrowse"
UserVariable.Add "Explore", "strExplore"
UserVariable.Add "Manage", "strManage"
UserVariable.Add "Search", "strSearch"
UserVariable.Add "Show on Desktop", "strShowOnDesktop"
UserVariable.Add "Hide from Desktop", "strHideFromDesktop"
UserVariable.Add "Show in Computer", "strShowInComputer"
UserVariable.Add "Hide from Computer", "strHideFromComputer"
UserVariable.Add "Open", "strOpen"
UserVariable.Add "Don't show option in navigation pane", "strHideOption"
UserVariable.Add "Don't pop out folder contents", "strDontPopOut"
UserVariable.Add "Pop out folder contents", "strPopOut"
UserVariable.Add "Rename", "strRename"
UserVariable.Add "Send to Desktop", "strCopyToDesktop"
UserVariable.Add "Send to ViPad", "strCopyToViPad"
UserVariable.Add "Properties", "strProperties"
UserVariable.Add "Collapse", "strCollapse"
UserVariable.Add "Expand", "strExpand"
UserVariable.Add "Run as administrator", "strRunAsAdmin"
UserVariable.Add "Unpin from Start Menu", "strUnpinToStartMenu"
UserVariable.Add "Pin To Start Menu", "strPinToStartMenu"
UserVariable.Add "Remove from this list", "strRemoveFromList"
UserVariable.Add "Programs", "strPrograms"
UserVariable.Add "Files", "strFiles"
UserVariable.Add "All files", "strAllExtensions"
UserVariable.Add "Documents", "strDocuments"
UserVariable.Add "Pictures", "strPictures"
UserVariable.Add "Music", "strMusic"
UserVariable.Add "Videos", "strVideos"
UserVariable.Add "Games", "strGames"
UserVariable.Add "Recent", "strRecent"
UserVariable.Add "Computer", "strComputer"
UserVariable.Add "Network", "strNetwork"
UserVariable.Add "Connect To", "strConnectTo"
UserVariable.Add "Control Panel", "strControlPanel"
UserVariable.Add "Help and Support", "strHelp"
UserVariable.Add "Printers and Faxes", "strPrinters"
UserVariable.Add "Set Program Access and Defaults", "strSetDefaults"
UserVariable.Add "Libraries", "strLibraries"
UserVariable.Add "Downloads", "strDownloads"
UserVariable.Add "3D Objects", "strObjects"
UserVariable.Add "ViStart Control panel", "strViStartControlPanel"
UserVariable.Add "Style", "strStyle"
UserVariable.Add "Configure", "strConfigure"
UserVariable.Add "Desktop", "strDesktop"
UserVariable.Add "Start Menu Skin", "strWhichStartMenu"
UserVariable.Add "Install...", "strInstall"
UserVariable.Add "Select a new ViStart theme file", "strViStartTheme"
UserVariable.Add "Start Orb Skin", "strWhatStarOrb"
UserVariable.Add "Use Skin default Orb", "strSkinDefaultOrb"
UserVariable.Add "Pick image...", "strPick"
UserVariable.Add "Choose new Start Button image", "strViStartOrb"
UserVariable.Add "Rollover Skin", "strWhatRollover"
UserVariable.Add "Use Skin default Rollover", "strSkinDefaultRollover"
UserVariable.Add "Visibility settings", "strWhatToSee"
UserVariable.Add "Default settings for Start menu items", "strWhatToSeeOnRight"
UserVariable.Add "Show program menu first", "strProgramsFirst"
UserVariable.Add "Show user picture", "strShowUserPicture"
UserVariable.Add "Don't show item", "strDontShowItem"
UserVariable.Add "Display item as link", "strDisplayAsLink"
UserVariable.Add "Display item as menu", "strDisplayAsMenu"
UserVariable.Add "Set default desktop actions", "strDesktopSettings"
UserVariable.Add "Both Windows Keys show ViStart", "strBothWinKeysViStart"
UserVariable.Add "[Left Windows Key] shows ViStart", "strLeftWinKey"
UserVariable.Add "[Right Windows Key] shows ViStart", "strRightWinKey"
UserVariable.Add "Both Windows keys shows Windows Menu", "strBothWinKeys"
UserVariable.Add "Start button shows ViStart", "strStartViStart"
UserVariable.Add "Start button shows the Windows menu", "strStartWinMenu"
UserVariable.Add "Restore Windows Start Menu Shortcut", "strRestoreStartMenu"
UserVariable.Add "Windows 8 exclusive features defaults", "strW8Features"
UserVariable.Add "Disable all Windows 8 hot corners", "strHotCorners"
UserVariable.Add "Disable CharmsBar", "strDisableCharmsBar"
UserVariable.Add "Disable Drag to close", "strDisableDragToClose"
UserVariable.Add "Disable bottom left (Start) hot corner", "strDisableBottomLeftCorner"
UserVariable.Add "Automatically go to desktop when I log in", "strSkipMetroScreen"
UserVariable.Add "Windows 8 related features require a restart to take effect", "strW8FeaturesWarning"
UserVariable.Add "(ViStart the program itself is created by Lee Matthew Chantrey)", "strCopyright"
If g_Windows8 Or g_Windows81 Then
UserVariable.Add "Metro", "startmenu"
Else
UserVariable.Add "Start Menu", "startmenu"
End If
UserVariable.Add App.Path, "apppath"
UserVariable.Add ShellHelper.GetFolderPathVB(5), "CSIDL_PERSONAL"
UserVariable.Add ShellHelper.GetFolderPathVB(39), "CSIDL_MYPICTURES"
UserVariable.Add ShellHelper.GetFolderPathVB(&HD), "CSIDL_MYMUSIC"
UserVariable.Add ShellHelper.GetFolderPathVB(&HE), "CSIDL_MYVIDEO"
UserVariable.Add ShellHelper.GetFolderPathVB(&H8), "CSIDL_RECENT"
UserVariable.Add ShellHelper.GetFolderPathVB(18), "CSIDL_NETWORK"
If Not xmlLanguageFile.Load(szSourceFile) Then
Exit Function
End If
XML_PopulateStrings xmlLanguageFile.firstChild
End Function
Public Function ShowNormalWindowsMenu()
SetForegroundWindow g_lnghwndTaskBar
g_ignoreHook = True
SetKeyDown VK_LWINKEY
SetKeyUp VK_LWINKEY
g_ignoreHook = False
End Function
Public Function IsRectDifferent(ByRef rect1 As RECT, ByRef rect2 As RECT) As Boolean
If rect1.Left <> rect2.Left Or _
rect1.Right <> rect2.Right Or _
rect1.Top <> rect2.Top Or _
rect1.Bottom <> rect2.Bottom Then
IsRectDifferent = True
End If
End Function
Public Function MakeLayerdWindow(ByRef sourceForm As Form) As LayerdWindowHandles
Dim srcPoint As POINTL
Dim winSize As SIZEL
Dim mDC As Long
Dim tempBI As BITMAPINFO
Dim curWinLong As Long
Dim mainBitmap As Long
Dim oldBitmap As Long
Dim theHandles As New LayerdWindowHandles
With tempBI.bmiHeader
.biSize = Len(tempBI.bmiHeader)
.biBitCount = 32 ' Each pixel is 32 bit's wide
.biHeight = sourceForm.ScaleHeight ' Height of the form
.biWidth = sourceForm.ScaleWidth ' Width of the form
.biPlanes = 1 ' Always set to 1
.biSizeImage = .biWidth * .biHeight * (.biBitCount / 8) ' This is the number of bytes that the bitmap takes up. It is equal to the Width*Height*ByteCount (bitCount/8)
End With
mDC = CreateCompatibleDC(sourceForm.hdc)
mainBitmap = CreateDIBSection(mDC, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
If mainBitmap = 0 Then
MsgBox "CreateDIBSection Failed", vbCritical
End If
oldBitmap = SelectObject(mDC, mainBitmap) ' Select the new bitmap, track the old that was selected
If oldBitmap = 0 Then
MsgBox "SelectObject Failed", vbCritical
End If
curWinLong = GetWindowLong(sourceForm.hWnd, GWL_EXSTYLE)
If SetWindowLong(sourceForm.hWnd, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED Or WS_EX_TOOLWINDOW) = 0 Then
'Logger.Error "Failed to create layered window", "Startbar_Support"
'Exit Function
End If
' Needed for updateLayeredWindow call
srcPoint.X = 0
srcPoint.Y = 0
winSize.cx = sourceForm.ScaleWidth
winSize.cy = sourceForm.ScaleHeight
theHandles.mainBitmap = mainBitmap
theHandles.oldBitmap = oldBitmap
theHandles.theDC = mDC
theHandles.SetSize winSize
theHandles.SetPoint srcPoint
'theHandles.
Set MakeLayerdWindow = theHandles
End Function
Sub SendKeyToSearchBox(lngKeyCode As Long)
If Not (lngKeyCode = vbKeyUp Or _
lngKeyCode = vbKeyDown Or _
lngKeyCode = vbKeyRight Or _
lngKeyCode = vbKeyLeft) Then
'frmStartMenuBase.SearchBox_Focus
txtSearch.clicked
End If
End Sub
Sub SetDefaultFont_IfNeeded()
If Not g_DefaultFont Is Nothing Then Exit Sub
Set g_DefaultFont = New GDIFont
Set g_DefaultFontItalic = New GDIFont
If FontExists("Tahoma") Then
OptionsHelper.PrimaryFont = "Tahoma"
OptionsHelper.SecondaryFont = "Tahoma"
sVar_sFontName = "Tahoma"
If FontExists("Segoe UI") Then
OptionsHelper.PrimaryFont = "Segoe UI"
sVar_sFontName = "Segoe UI"
End If
Else
MsgBox "A compatible font was not found. Please install Tahoma and Segoe UI", vbCritical
End If
g_DefaultFont.Constructor OptionsHelper.PrimaryFont
g_DefaultFontItalic.Constructor OptionsHelper.PrimaryFont, , APITRUE
End Sub
Sub SetVars_IfNeeded()
If sCon_AppDataPath <> vbNullString Then
Exit Sub
End If
AppPath = App.Path
If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
sCon_AppDataPath = Environ$("appdata") & "\ViStart\"
If Not FSO.FolderExists(sCon_AppDataPath) Then
If FSO.FolderExists(App.Path & "\_skins\") Then
' ViStart %APPDATA% folder doesn't exist _skins are present in same directory
sCon_AppDataPath = App.Path
End If
End If
If Not FSO.FolderExists(sCon_AppDataPath) Then
FSO.CreateFolder sCon_AppDataPath
If Err Then
MsgBox Err.Description, vbCritical
ExitApplication
End
Exit Sub
End If
End If
Dim currentUserShellFoldersRegKey As RegistryKey
Dim localMachineShellFoldersRegKey As RegistryKey
Set currentUserShellFoldersRegKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
Set localMachineShellFoldersRegKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
If Not currentUserShellFoldersRegKey Is Nothing Then
sVar_Reg_StartMenu_MyDocuments = currentUserShellFoldersRegKey.GetValue("Personal")
If (LenB(sVar_Reg_StartMenu_MyDocuments) = 0) Then
MsgBox "RegFail: My Documents Shell Folder not found", vbCritical
End
End If
sVar_Reg_StartMenu_CurrentUser = currentUserShellFoldersRegKey.GetValue("Start Menu")
If (LenB(sVar_Reg_StartMenu_CurrentUser) = 0) Then
MsgBox "RegFail: Current User User Start Menu not found", vbCritical
End
End If
sVar_Reg_StartMenu_CurrentUserPrograms = currentUserShellFoldersRegKey.GetValue("Programs")
If (LenB(sVar_Reg_StartMenu_CurrentUserPrograms) = 0) Then
MsgBox "RegFail: Start Menu Current User Programs not found", vbCritical
End
End If
sVar_Reg_StartMenu_CurrentUserRecentItems = currentUserShellFoldersRegKey.GetValue("Recent")
If (LenB(sVar_Reg_StartMenu_CurrentUserRecentItems) = 0) Then
bHasRecentItems = False
Else
bHasRecentItems = True
End If
End If
If Not localMachineShellFoldersRegKey Is Nothing Then
sVar_Reg_StartMenu_CommonUser = localMachineShellFoldersRegKey.GetValue("Common Start Menu")
If (LenB(sVar_Reg_StartMenu_CommonUser) = 0) Then
MsgBox "RegFail: Common User Start Menu not found", vbCritical
End
End If
sVar_Reg_StartMenu_CommonPrograms = localMachineShellFoldersRegKey.GetValue("Common Programs")
If (LenB(sVar_Reg_StartMenu_CommonPrograms) = 0) Then
MsgBox "RegFail: Start Menu Common Programs not found", vbCritical
End
End If
End If
Dim userShellFoldersRegKey As RegistryKey
Dim userProfileDesktopKeyValue As String
Set userShellFoldersRegKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders")
If Not userShellFoldersRegKey Is Nothing Then
userProfileDesktopKeyValue = userShellFoldersRegKey.GetValue("Desktop", "%userprofile%\desktop")
Else
userProfileDesktopKeyValue = "%userprofile%\desktop"
End If
sVar_Reg_Desktop = VarScan(userProfileDesktopKeyValue)
sCon_OrbFolderPath = sCon_AppDataPath & "_orbs\"
If Not FSO.FolderExists(sCon_OrbFolderPath) Then
FSO.CreateFolder sCon_OrbFolderPath
End If
End Sub
Private Sub XML_PopulateStrings(ByRef ObjXML As IXMLDOMElement)
Dim objStrings As IXMLDOMElement
Dim objString As IXMLDOMElement
Dim thisObject As Object
On Error GoTo Handler
'Set objStrings = ObjXML.selectSingleNode("/strings")
' iterate its string children
For Each thisObject In ObjXML.childNodes
If TypeName(thisObject) = "IXMLDOMElement" Then
Set objString = thisObject
' get all the strings
If objString.nodeName = "string" Then
If AttributeExists(objString, "id") = False Or _
AttributeExists(objString, "value") = False Then
MsgBox "id or value not found in string", vbCritical
End
Else
If UpdateColValue(UserVariable, CStr(objString.Attributes.getNamedItem("id").text), CStr(objString.Attributes.getNamedItem("value").text)) = False Then
Logger.Error "'" & CStr(objString.Attributes.getNamedItem("id").text) & "' is not a known string identifier", ""
End If
End If
End If
End If
Next
Exit Sub
Handler:
Logger.Error Err.Description, "XML_PopulateStrings"
End Sub
Public Function AttributeExists(ByRef objElem As MSXML2.IXMLDOMElement, ByVal sAttribName As String) As Boolean
Dim i As Integer
Dim objAttribs As IXMLDOMAttribute
For Each objAttribs In objElem.Attributes
If objAttribs.Name = sAttribName Then
AttributeExists = True
Exit Function
End If
Next
End Function
Public Function FolderExists(sSource As String) As Boolean
FolderExists = FSO.FolderExists(sSource)
End Function
Public Function FileExists(sSource As String) As Boolean
FileExists = FSO.FileExists(sSource)
End Function
Public Function GetTarget(strPath As String) As String
Dim c As Integer
Dim s As Integer
Dim J As Integer
c = 0
s = 0
J = 0
For m = 1 To Len(Path)
GetChr0 = Right$(Path, m)
GetChr1 = Left$(GetChr0, 1)
If GetChr1 = "\" Or GetChr1 = "/" Then
c = c + 1
End If
Next m
For m = 1 To Len(Path)
GetChr0 = Left$(Path, m)
GetChr1 = Right$(GetChr0, 1)
J = J + 1
If GetChr1 = "\" Or GetChr1 = "/" Then
J = 0
s = s + 1
If s = c Then
GetTarget = Right$(GetChr0, m - J)
Exit Function
End If
End If
Next m
End Function
Public Function GetFileDateLastAccessed(ByVal theFilePath As String) As Date
Dim thisFile As Scripting.File
If FSO.FileExists(theFilePath) = False Then
Exit Function
End If
Set thisFile = FSO.GetFile(theFilePath)
GetFileDateLastAccessed = CDate(thisFile.DateLastAccessed)
End Function
Public Sub ReverseArray(ByRef pvarArray As Variant)
Dim arrIndex As Long
Dim varSwapTo
Dim swapFrom As Long
Dim countBackward As Long
If IsArrayInitialized(pvarArray) = False Then
Exit Sub
End If
For arrIndex = LBound(pvarArray) To UBound(pvarArray) / 2
swapFrom = UBound(pvarArray) - countBackward
varSwapTo = pvarArray(swapFrom)
pvarArray(swapFrom) = pvarArray(arrIndex)
pvarArray(arrIndex) = varSwapTo
countBackward = countBackward + 1
Next
End Sub
' Omit plngLeft & plngRight; they are used internally during recursion
Public Sub QuickSort_FileAccessed(ByRef pvarArray As Variant, Optional ByVal plngLeft As Long, Optional ByVal plngRight As Long)
Dim lngFirst As Long
Dim lngLast As Long
Dim varMid As Variant
Dim varSwap As Variant
If IsArrayInitialized(pvarArray) = False Then
Exit Sub
End If
If plngRight = 0 Then
plngLeft = LBound(pvarArray)
plngRight = UBound(pvarArray)
End If
lngFirst = plngLeft
lngLast = plngRight
varMid = pvarArray((plngLeft + plngRight) \ 2)
Do
Do While GetFileDateLastAccessed(pvarArray(lngFirst)) < GetFileDateLastAccessed(varMid) And lngFirst < plngRight
lngFirst = lngFirst + 1
Loop
Do While GetFileDateLastAccessed(varMid) < GetFileDateLastAccessed(pvarArray(lngLast)) And lngLast > plngLeft
lngLast = lngLast - 1
Loop
If lngFirst <= lngLast Then
varSwap = pvarArray(lngFirst)
pvarArray(lngFirst) = pvarArray(lngLast)
pvarArray(lngLast) = varSwap
lngFirst = lngFirst + 1
lngLast = lngLast - 1
End If
Loop Until lngFirst > lngLast
If plngLeft < lngLast Then QuickSort_FileAccessed pvarArray, plngLeft, lngLast
If lngFirst < plngRight Then QuickSort_FileAccessed pvarArray, lngFirst, plngRight
End Sub
Function QuickSortNamesAscending( _
ByVal col_sCollectionToAlphabetize As Collection, _
ByVal iSortType As VbCompareMethod) As Collection
On Error GoTo Handler
Dim iEachItem As Long
Dim col_sSorted As New Collection
Dim fOrderNotChanged As Boolean
Dim arr_sSortItems() As String
Dim sFirstString As String
Dim iNumberOfItems As Long
iNumberOfItems = col_sCollectionToAlphabetize.count
If iNumberOfItems = 0 Then
Set QuickSortNamesAscending = col_sCollectionToAlphabetize
Exit Function
End If
'convert to an array
ReDim arr_sSortItems(iNumberOfItems - 1)
For iEachItem = 1 To iNumberOfItems
arr_sSortItems(iEachItem - 1) = col_sCollectionToAlphabetize(iEachItem)
Next iEachItem
Do
fOrderNotChanged = True
For iEachItem = 1 To iNumberOfItems - 1
If Strings.StrComp(Split(arr_sSortItems(iEachItem - 1), "*")(0), Split(arr_sSortItems(iEachItem), "*")(0), iSortType) = 1 Then
'swap the values
sFirstString = arr_sSortItems(iEachItem - 1)
arr_sSortItems(iEachItem - 1) = arr_sSortItems(iEachItem)
arr_sSortItems(iEachItem) = sFirstString
fOrderNotChanged = False
End If
Next iEachItem
'do this until no changes were needed
Loop Until fOrderNotChanged
'convert back to an array
For iEachItem = 0 To iNumberOfItems - 1
col_sSorted.Add arr_sSortItems(iEachItem)
Next iEachItem
Set QuickSortNamesAscending = col_sSorted
Exit Function
Handler:
Logger.Error Err.Description, "QuickSortNamesAsc"
End Function
Public Function UpdateCol(ByRef Col As Collection, index, vUpdate, Optional sKey As String) As Boolean
'Updates Collection Key, Keeps Numerical Index intact
On Error GoTo Handler
Col.Remove index
If Col.count + 1 > index Then
Col.Add vUpdate, sKey, index
Else
Col.Add vUpdate, sKey
End If
UpdateCol = True
Exit Function
Handler:
UpdateCol = False
End Function
Public Function IsObjectSet(AnObject As Object) As Boolean
Dim X As String
' Returns true if an object variable is initialized
' you figure this out
X = TypeName(AnObject)
If X = "Nothing" Then
IsObjectSet = False
Else
IsObjectSet = True
End If
End Function
Public Function ExistCol(ByRef Col As Collection, index) As Boolean
'Updates Collection Key, Keeps Numerical Index intact
On Error GoTo Handler
If IsObject(Col(index)) Then
End If
ExistCol = True
Exit Function
Handler:
ExistCol = False
End Function
Public Function UpdateColValue(ByRef Col As Collection, index, vUpdate) As Boolean
'Updates Collection Key, Keeps Numerical Index intact
On Error GoTo Handler
Col.Remove index
Col.Add vUpdate, index
UpdateColValue = True
Exit Function
Handler:
UpdateColValue = False
End Function
Public Function ObjectCaptionString(ByRef objSource As Object) As String
Dim strOutput As String
On Error Resume Next
strOutput = "[Object#2];"
strOutput = strOutput & "Caption:" & objSource.Caption & "-"
ObjectCaptionString = strOutput
End Function
Public Function ObjectChildrenCount(ByRef objSource As Object) As String
Dim strOutput As String
On Error Resume Next
strOutput = "[Object#3];"
strOutput = strOutput & "Children:" & objSource.Children.count & "-"
ObjectChildrenCount = strOutput
End Function
Public Function ObjectPathNameToString(ByRef objSource As Object) As String
Dim strOutput As String
On Error Resume Next
strOutput = "[Object#1];"
strOutput = strOutput & "Name:" & objSource.Name & "-"
strOutput = strOutput & "Path:" & objSource.Path
ObjectPathNameToString = strOutput
End Function
Public Function GetPublicString(ByVal stringID As String, Optional Default As String = vbNullString)
On Error GoTo Handler
GetPublicString = UserVariable(stringID)
Exit Function
Handler:
GetPublicString = Default
End Function
Public Function FontExists(FontName As String) As Boolean
Dim oFont As New StdFont
Dim bAns As Boolean
oFont.Name = FontName
bAns = StrComp(FontName, oFont.Name, vbTextCompare) = 0
FontExists = bAns
End Function
Public Function MouseInsideWindow(hWnd As Long) As Boolean
Dim WinRect As win.RECT
Dim cursorPosition As win.POINTL
GetWindowRect hWnd, WinRect
GetCursorPos cursorPosition
If IsWindowVisible(hWnd) = APITRUE Then
If cursorPosition.X > WinRect.Left And _
cursorPosition.Y > WinRect.Top And _
cursorPosition.Y < WinRect.Bottom And _
cursorPosition.X < WinRect.Right Then
MouseInsideWindow = True
End If
End If
End Function
Public Function ViElementToAllPrograms(srcViElement As IXMLDOMElement) As AllProgramsText
On Error Resume Next
Dim returnRect As New AllProgramsText
With returnRect
.Visible = True
.Style = FontStyleRegular
.Left = srcViElement.getAttribute("x")
.Top = srcViElement.getAttribute("y")
.Height = srcViElement.getAttribute("height")
.Width = srcViElement.getAttribute("width")
Select Case UCase$(srcViElement.getAttribute("style"))
Case "BOLD"
.Style = FontStyleBold
Case "ITALIC"
.Style = FontStyleItalic
Case "BOLD ITALIC"
.Style = FontStyleBoldItalic
Case "UNDERLINE"
.Style = FontStyleUnderline
End Select
End With
Set ViElementToAllPrograms = returnRect
End Function
Public Function ViElementFromXML(srcViElement As IXMLDOMElement) As GenericViElement
On Error Resume Next
Dim returnRect As New GenericViElement
With returnRect
.Visible = True
.Left = srcViElement.getAttribute("x")
.Top = srcViElement.getAttribute("y")
.Height = srcViElement.getAttribute("height")
.Width = srcViElement.getAttribute("width")
.Visible = srcViElement.getAttribute("visible")
.FontID = srcViElement.getAttribute("font")
.BackColour = CLng(HEXCOL2RGB(srcViElement.getAttribute("backcolour")))
End With
Set ViElementFromXML = returnRect
End Function
Function EnumTaskbarChildrenToFindStartButton(ByVal lHWnd As Long, ByVal lParam As Long) _
As Long
Dim RetVal As Long
Dim WinClassBuf As String * 255, WinTitleBuf As String * 255
Dim WinClass As String, WinTitle As String
RetVal = GetClassName(lHWnd, WinClassBuf, 255)
WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces
RetVal = GetWindowText(lHWnd, WinTitleBuf, 255)
WinTitle = StripNulls(WinTitleBuf)
If LCase$(WinClass) = "start" And LCase$(WinTitle) = "start" Then
lParam = lHWnd
g_hwndStartButton = lHWnd
EnumChildProc = False
Else
EnumChildProc = True
End If
End Function