-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcommon.bas
2375 lines (1849 loc) · 92 KB
/
common.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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "common"
' .01 DAEB 23/01/2021 common.bas calls twipsperpixelsX/Y function when determining the twips for high DPI screens
' .02 DAEB 25/01/2021 common.bas Moved from mdlmain.bas to common to ensure the checkSteamyDockInstalled subroutine can be run from anywhere, specifically for the variable sdAppPath
' .03 DAEB 31/01/2021 common.bas Added new checkbox to determine if a post initiation dialog should appear
' .04 DAEB 06/03/2021 common.bas Moved from main code form to common to ensure the locateDockSettingsFile subroutine is common to all
' .05 DAEB 01/04/2021 common.bas Added declaration to allow replacement of some modal msgbox with the non-modal versions
' .06 DAEB 19/04/2021 common.bas moved to the common area so that it can be used by each of the utilities
' .07 DAEB 26/04/2021 common.bas changed to use pixels alone, removed all unnecessary twip conversion
' .08 DAEB 11/05/2021 common.bas Added function to pad a string similar to the VB.NET padRight & padLeft functions.
' .09 DAEB 11/05/2021 common.bas Added function to align and centre a string so it can appear in a msgbox neatly.
' .10 DAEB 20/05/2021 common.bas Added new check box to allow a quick launch of the chosen app
' .11 DAEB 21/05/2021 common.bas Added new field for second program to be run
' .12 DAEB 20/05/2021 common.bas Added new check box to allow autohide of the dock after launch of the chosen app
Option Explicit
'------------------------------------------------------------
' common.bas
'
' Public procedures that appear in all three programs as an included module common.bas,
'
' Note: If you make a change here it affects all three programs dynamically
'------------------------------------------------------------
' APIs and variables for querying processes START
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 260
End Type
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Const TH32CS_SNAPPROCESS As Long = 2&
Private uProcess As PROCESSENTRY32
Private hSnapshot As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" (ByVal hSnapshot As Long, ByRef uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" (ByVal hSnapshot As Long, ByRef uProcess As PROCESSENTRY32) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" (ByVal lFlags As Long, ByRef lProcessID As Long) As Long ' Alias "CreateToolhelp32Snapshot"
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
' APIs for querying processes END
' functions to determine 64bitness start
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProc As Long, bWow64Process As Boolean) As Long
' functions to determine 64bitness END
' enumerate variables for folder values start
Public Enum eSpecialFolders
SpecialFolder_AppData = &H1A 'for the current Windows user, on any computer on the network [Windows 98 or later]
SpecialFolder_CommonAppData = &H23 'for all Windows users on this computer [Windows 2000 or later]
SpecialFolder_LocalAppData = &H1C 'for the current Windows user, on this computer only [Windows 2000 or later]
SpecialFolder_Documents = &H5 'the Documents folder for the current Windows user
End Enum
' enumerate variables for folder values END
'API Function to read/write information from INI File start
Private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any _
, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long _
, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any _
, ByVal lpString As Any, ByVal lpFileName As String) As Long
'API Function to read/write information from INI File start
' APIs, constants defined for querying the registry STARTS
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Public Const REG_SZ = 1 ' Unicode nul terminated string
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Any, ByVal cbData As Long) As Long
' APIs, constants defined for querying the registry ENDS
' APIs and structures for opening a common dialog box to select files without OCX dependencies STARTS
Private Enum FileOpenConstants
'ShowOpen, ShowSave constants.
cdlOFNAllowMultiselect = &H200&
cdlOFNCreatePrompt = &H2000&
cdlOFNExplorer = &H80000
cdlOFNExtensionDifferent = &H400&
cdlOFNFileMustExist = &H1000&
cdlOFNHideReadOnly = &H4&
cdlOFNLongNames = &H200000
cdlOFNNoChangeDir = &H8&
cdlOFNNoDereferenceLinks = &H100000
cdlOFNNoLongNames = &H40000
cdlOFNNoReadOnlyReturn = &H8000&
cdlOFNNoValidate = &H100&
cdlOFNOverwritePrompt = &H2&
cdlOFNPathMustExist = &H800&
cdlOFNReadOnly = &H1&
cdlOFNShareAware = &H4000&
End Enum
Public Type OPENFILENAME
lStructSize As Long 'The size of this struct (Use the Len function)
hWndOwner As Long 'The hWnd of the owner window. The dialog will be modal to this window
hInstance As Long 'The instance of the calling thread. You can use the App.hInstance here.
lpstrFilter As String 'Use this to filter what files are showen in the dialog. Separate each filter with Chr$(0). The string also has to end with a Chr(0).
lpstrCustomFilter As String 'The pattern the user has choosed is saved here if you pass a non empty string. I never use this one
nMaxCustFilter As Long 'The maximum saved custom filters. Since I never use the lpstrCustomFilter I always pass 0 to this.
nFilterIndex As Long 'What filter (of lpstrFilter) is showed when the user opens the dialog.
lpstrFile As String 'The path and name of the file the user has chosed. This must be at least MAX_PATH (260) character long.
nMaxFile As Long 'The length of lpstrFile + 1
lpstrFileTitle As String 'The name of the file. Should be MAX_PATH character long
nMaxFileTitle As Long 'The length of lpstrFileTitle + 1
lpstrInitialDir As String 'The path to the initial path :) If you pass an empty string the initial path is the current path.
lpstrTitle As String 'The caption of the dialog.
flags As FileOpenConstants 'Flags. See the values in MSDN Library (you can look at the flags property of the common dialog control)
nFileOffset As Integer 'Points to the what character in lpstrFile where the actual filename begins (zero based)
nFileExtension As Integer 'Same as nFileOffset except that it points to the file extention.
lpstrDefExt As String 'Can contain the extention Windows should add to a file if the user doesn't provide one (used with the GetSaveFileName API function)
lCustData As Long 'Only used if you provide a Hook procedure (Making a Hook procedure is pretty messy in VB.
lpfnHook As Long 'Pointer to the hook procedure.
lpTemplateName As String 'A string that contains a dialog template resource name. Only used with the hook procedure.
End Type
Public Declare Function GetOpenFileName Lib "comdlg32" Alias "GetOpenFileNameA" ( _
lpofn As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32" Alias "GetSaveFileNameA" ( _
lpofn As OPENFILENAME) As Long
Public OF As OPENFILENAME
Public x_OpenFilename As OPENFILENAME
Private Type BROWSEINFO
hWndOwner As Long
pidlRoot As Long 'LPCITEMIDLIST
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long 'BFFCALLBACK
lParam As Long
iImage As Long
End Type
Private Declare Function SHBrowseForFolderA Lib "shell32.dll" (binfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidl&, ByVal szPath$) As Long
Private Declare Function CoTaskMemFree Lib "ole32.dll" (lp As Any) 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
' APIs and structures for opening a common dialog box to select files without OCX dependencies STARTS
' Rocketdock compatible icon global variables START
Public sFilename As String
Public sFileName2 As String
Public sTitle As String
Public sCommand As String
Public sArguments As String
Public sWorkingDirectory As String
Public sShowCmd As String
Public sOpenRunning As String
Public sRunElevated As String
Public sIsSeparator As String
Public sUseContext As String
Public sDockletFile As String
Public sUseDialog As String
Public sUseDialogAfter As String ' .03 DAEB 31/01/2021 common.bas Added new checkbox to determine if a post initiation dialog should appear
Public sQuickLaunch As String ' .10 DAEB 20/05/2021 common.bas Added new check box to allow a quick launch of the chosen app
Public sAutoHideDock As String ' .12 DAEB 20/05/2021 common.bas Added new check box to allow autohide of the dock after launch of the chosen app
Public sSecondApp As String ' .11 DAEB 21/05/2021 common.bas Added new field for second program to be run
Public sRunSecondAppBeforehand As String
Public sAppToTerminate As String
Public sDisabled As String
' Rocketdock icon global variables END
Public usedMenuFlag As Boolean
Public dockSettingsFile As String
Public toolSettingsFile As String
'Public origSettingsFile As String
Public RDinstalled As String
Public RD86installed As String
Public RDregistryPresent As Boolean
Public rocketDockInstalled As Boolean
Public rdAppPath As String
' .02 STARTS DAEB 25/01/2021 Moved from mdlmain.bas to common to ensure the checkSteamyDockInstalled subroutine can be run from anywhere, specifically for the variable sdAppPath
Public sdAppPath As String
Public SDinstalled As String
Public SD86installed As String
Public dockAppPath As String
Public steamyDockInstalled As Boolean
Public defaultDock As Integer
' .02 ENDS DAEB 25/01/2021 Moved from mdlmain.bas to common to ensure the checkSteamyDockInstalled subroutine can be run from anywhere, specifically for the variable sdAppPath
Public rdIconCount As Integer
Public requiresAdmin As Boolean
Public rDRunAppInterval As String
Public rDAlwaysAsk As String
Public rDGeneralReadConfig As String
Public rDGeneralWriteConfig As String
Public rDSkinTheme As String
Public rDDefaultDock As String
Public rDLockIcons As String
Public rDRetainIcons As String ' .18 DAEB 07/09/2022 docksettings save and restore the chkRetainIcons checkbox value
Public rDOpenRunning As String
Public rDShowRunning As String
Public rDManageWindows As String
Public rDDisableMinAnimation As String
Public sDDockSettingsDefaultEditor As String
Public sDIconSettingsDefaultEditor As String
Public sDDockDefaultEditor As String
Public rDDebugFlg As String
Public sixtyFourBit As Boolean
Public rDCustomIconFolder As String
Public classicThemeCapable As Boolean
Private lstDevices(1, 25) As String
Private lstDevicesListCount As Integer
Public sAllDrives As String
' Steamydock global configuration variables END
' APIs for useful functions START
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
Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
' APIs for useful functions END
' APIs and variables for querying running processes' paths START
Private Const PROCESS_QUERY_INFORMATION As Long = &H400
Private Const PROCESS_VM_READ As Long = (&H10)
Private Const API_NULL As Long = 0
Private Declare Function GetProcessImageFileName Lib "psapi.dll" Alias "GetProcessImageFileNameA" (ByVal hProcess As Long, ByVal lpImageFileName As String, ByVal nSize As Long) As Long
' APIs and variables for querying running processes' paths ENDS
' APIs and variables for querying running processes' paths ENDS
Private Declare Function QueryDosDeviceW Lib "kernel32.dll" (ByVal lpDeviceName As Long, ByVal lpTargetPath As Long, ByVal ucchMax As Long) As Long
Private Declare Function GetLogicalDriveStringsA Lib "kernel32" (ByVal nBufferLength As Long, lpBuffer As Any) As Long
Private Declare Function GetDriveTypeA Lib "kernel32" (ByVal nDrive As String) As Long
' APIs and variables for querying running processes' paths ENDS
Public storeWindowHwnd As Long '.nn
' .05 DAEB 01/04/2021 common.bas Added declaration to allow replacement of some modal msgbox with the non-modal versions
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
' Flag for debug mode '.06 DAEB 19/04/2021 common.bas moved to the common area so that it can be used by each of the utilities
Private mbDebugMode As Boolean ' .30 DAEB 03/03/2021 frmMain.frm replaced the inIDE function that used a variant to one without
'------------------------------------------------------ STARTS
Private Const TIME_ZONE_ID_DAYLIGHT As Integer = 2
' Types for determining the timezone
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
bias As Long
StandardName(63) As Byte
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(63) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
' APIs for determining the timezone
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function GetMem4 Lib "msvbvm60" (ByRef Source As Any, ByRef Dest As Any) As Long ' Always ignore the returned value, it's useless.
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
'------------------------------------------------------ ENDS
Public msgBoxOut As Boolean
Public msgLogOut As Boolean
Public windowsVersionString As String
Public sDShowIconSettings As String ' .14 DAEB 01/05/2021 docksettings added checkbox and values to show icon settings utility when adding an icon to the dock
'------------------------------------------------------ STARTS
' For determining dir existence
Private Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function GetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long) As Long
'------------------------------------------------------ ENDS
'------------------------------------------------------ STARTS
' Constants for playing sounds
Public Const SND_ASYNC As Long = &H1 ' play asynchronously
Public Const SND_FILENAME As Long = &H20000 ' name is a file name
' APIs for playing sounds
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'------------------------------------------------------ ENDS
'
'---------------------------------------------------------------------------------------
' Procedure : checkLicenceState
' Author : beededea
' Date : 20/06/2019
' Purpose : check the state of the licence
'---------------------------------------------------------------------------------------
'
Public Sub checkLicenceState()
Dim slicence As String: slicence = "0"
On Error GoTo checkLicenceState_Error
If debugflg = 1 Then debugLog "%" & " sub checkLicenceState"
'toolSettingsFile = App.Path & "\settings.ini"
' read the tool's own settings file (
If fFExists(toolSettingsFile) Then ' does the tool's own settings.ini exist?
slicence = GetINISetting("Software\DockSettings", "Licence", toolSettingsFile)
' if the licence state is not already accepted then display the licence form
If slicence = "0" Then
Call LoadFileToTB(licence.txtLicenceTextBox, App.Path & "\licence.txt", False)
licence.Show vbModal ' show the licence screen in VB modal mode (ie. on its own)
' on the licence box change the state fo the licence acceptance
End If
End If
' show the licence screen if it has never been run before and set it to be in focus
If licence.Visible = True Then
licence.SetFocus
End If
On Error GoTo 0
Exit Sub
checkLicenceState_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure checkLicenceState of Form common"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : LoadFileToTB
' Author : beededea
' Date : 26/08/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function LoadFileToTB(ByRef TxtBox As Object, ByVal FilePath As String, Optional ByVal Append As Boolean = False) As Boolean
'PURPOSE: Loads file specified by FilePath into textcontrol
'(e.g., Text Box, Rich Text Box) specified by TxtBox
'If Append = true, then loaded text is appended to existing
' contents else existing contents are overwritten
'Returns: True if Successful, false otherwise
Dim iFile As Integer: iFile = 0
Dim s As String: s = vbNullString
On Error GoTo LoadFileToTB_Error
'If debugFlg = 1 Then debugLog "%" & "LoadFileToTB"
'If debugFlg = 1 Then debugLog "%" & LoadFileToTB
If Dir$(FilePath) = vbNullString Then Exit Function
On Error GoTo ErrorHandler:
s = TxtBox.Text
iFile = FreeFile
Open FilePath For Input As #iFile
s = Input(LOF(iFile), #iFile)
If Append Then
TxtBox.Text = TxtBox.Text & s
Else
TxtBox.Text = s
End If
LoadFileToTB = True
ErrorHandler:
If iFile > 0 Then Close #iFile
On Error GoTo 0
Exit Function
LoadFileToTB_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure LoadFileToTB of Form common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : savestring
' Author : beededea
' Date : 05/07/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Sub savestring(ByRef hKey As Long, ByRef strPath As String, ByRef strvalue As String, ByRef strData As String)
Dim keyhand As Long: keyhand = 0
Dim R As Long: R = 0
On Error GoTo savestring_Error
R = RegCreateKey(hKey, strPath, keyhand)
R = RegSetValueEx(keyhand, strvalue, 0, REG_SZ, ByVal strData, Len(strData))
R = RegCloseKey(keyhand)
On Error GoTo 0
Exit Sub
savestring_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure savestring of Module Common"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : getstring
' Author : beededea
' Date : 05/07/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function getstring(ByRef hKey As Long, ByRef strPath As String, ByRef strvalue As String) As String
Dim keyhand As Long: keyhand = 0
Dim lResult As Long: lResult = 0
Dim strBuf As String: strBuf = vbNullString
Dim lDataBufSize As Long: lDataBufSize = 0
Dim intZeroPos As Integer: intZeroPos = 0
Dim rvar As Integer: rvar = 0
'in .NET the variant type will need to be replaced by object? This code will go altogether as .NET has native functions to read the registry
Dim lValueType As Variant ' cannot initialise
On Error GoTo getstring_Error
rvar = RegOpenKey(hKey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strvalue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String$(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strvalue, 0&, 0&, ByVal strBuf, lDataBufSize)
Dim ERROR_SUCCESS As Variant
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
getstring = Left$(strBuf, intZeroPos - 1)
Else
getstring = strBuf
End If
End If
End If
On Error GoTo 0
Exit Function
getstring_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getstring of Module Common"
End Function
'----------------------------------------
'Name: testWindowsVersion
'Description:
'----------------------------------------
Public Sub testWindowsVersion(ByRef classicThemeCapable As Boolean)
'=================================
'2000 / XP / NT / 7 / 8 / 10
'=================================
On Error GoTo testWindowsVersion_Error
' variables declared
Dim ProgramFilesDir As String: ProgramFilesDir = vbNullString
Dim strString As String: strString = vbNullString
Dim prg As String: prg = vbNullString
' other variable assignments
classicThemeCapable = False
windowsVersionString = vbNullString
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName")
windowsVersionString = strString
requiresAdmin = False
' ****** note that when running in compatibility mode the o/s will respond with "Windows XP"
' ****** The IDE runs in compatibility mode so it will report the wrong version and thence the incorrect working folder
'MsgBox windowsVersionString
If debugflg = 1 Then debugLog "%" & " sub classicThemeCapable"
'Get the value of "ProgramFiles", or "ProgramFilesDir"
Select Case windowsVersionString
Case "Microsoft Windows NT4"
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProgramFilesDir")
Case "Microsoft Windows 2000"
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProgramFilesDir")
Case "Microsoft Windows XP"
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
Case "Microsoft Windows 2003"
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProgramFilesDir")
Case "Microsoft Vista"
requiresAdmin = True
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProgramFilesDir")
Case "Microsoft 7"
requiresAdmin = True
classicThemeCapable = True
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProgramFilesDir")
Case Else ' Windows 8/10/11+
requiresAdmin = True
classicThemeCapable = False
strString = getstring(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
End Select
'MsgBox strString
prg = Environ$("ProgramFiles")
ProgramFilesDir = strString
If ProgramFilesDir = vbNullString Then ProgramFilesDir = prg ' 64bit systems
If Not fDirExists(ProgramFilesDir) Then
ProgramFilesDir = "c:\program files" ' 32 bit systems
End If
'If debugFlg = 1 Then debugLog "%" & "ProgramFilesDir = " & ProgramFilesDir
'======================================================
'END routine error handler
'======================================================
On Error GoTo 0: Exit Sub
testWindowsVersion_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure testWindowsVersion of Module Common"
End Sub
'
'---------------------------------------------------------------------------------------
' Procedure : GetINISetting
' Author : beededea
' Date : 05/07/2019
' Purpose : Get the INI Setting from the File
'---------------------------------------------------------------------------------------
'
Public Function GetINISetting(ByVal sHeading As String, ByVal sKey As String, ByRef sINIFileName As String) As String
On Error GoTo GetINISetting_Error
Const cparmLen = 500 ' maximum no of characters allowed in the returned string
Dim sReturn As String * cparmLen ' not going to initialise this with a 500 char string
Dim sDefault As String * cparmLen
Dim lLength As Long: lLength = 0
lLength = GetPrivateProfileString(sHeading, sKey, sDefault, sReturn, cparmLen, sINIFileName)
GetINISetting = Mid$(sReturn, 1, lLength)
On Error GoTo 0
Exit Function
GetINISetting_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetINISetting of Module Common"
End Function
'
'---------------------------------------------------------------------------------------
' Procedure : PutINISetting
' Author : beededea
' Date : 05/07/2019
' Purpose : Save INI Setting in the File
'---------------------------------------------------------------------------------------
'
Public Sub PutINISetting(ByVal sHeading As String, ByVal sKey As String, ByVal sSetting As String, ByRef sINIFileName As String)
On Error GoTo PutINISetting_Error
Dim aLength As Long: aLength = 0
aLength = WritePrivateProfileString(sHeading, sKey _
, sSetting, sINIFileName)
On Error GoTo 0
Exit Sub
PutINISetting_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure PutINISetting of Module Common"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : fFExists
' Author : beededea
' Date : 17/10/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function fFExists(ByRef OrigFile As String) As Boolean
'Dim FS As Object ' not going to initialise an object here
On Error GoTo fFExists_Error
'If debugFlg = 1 Then debugLog "%fFExists"
' Set FS = CreateObject("Scripting.FileSystemObject")
' fFExists = FS.FileExists(OrigFile)
' test to see if a file exists
Const INVALID_HANDLE_VALUE = -1&
fFExists = Not (GetFileAttributesW(StrPtr(OrigFile)) = INVALID_HANDLE_VALUE)
On Error GoTo 0
Exit Function
fFExists_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fFExists of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : fDirExists
' Author : beededea
' Date : 17/10/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function fDirExists(ByRef OrigFile As String) As Boolean
'Dim FS As Object ' not going to initialise an object here
On Error GoTo fDirExists_Error
'If debugFlg = 1 Then debugLog "%fDirExists"
' Set FS = CreateObject("Scripting.FileSystemObject")
' fDirExists = FS.FolderExists(OrigFile)
fDirExists = (GetFileAttributes(OrigFile) And vbDirectory + vbVolume) = vbDirectory
On Error GoTo 0
Exit Function
fDirExists_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fDirExists of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : SpecialFolder
' Author : si_the_geek vbforums
' Date : 17/10/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function SpecialFolder(pFolder As eSpecialFolders) As String
'Returns the path to the specified special folder (AppData etc)
Dim objShell As Object ' not going to initialise an object here
Dim objFolder As Object
On Error GoTo SpecialFolder_Error
'If debugFlg = 1 Then debugLog "%SpecialFolder"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(CLng(pFolder))
If (Not objFolder Is Nothing) Then SpecialFolder = objFolder.Self.Path
Set objFolder = Nothing
Set objShell = Nothing
If SpecialFolder = vbNullString Then Err.Raise 513, "SpecialFolder", "The folder path could not be detected"
On Error GoTo 0
Exit Function
SpecialFolder_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SpecialFolder of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : checkAndKill
' Author : beededea
' Date : 21/09/2019
' Purpose : Find and kill any given process name
' : This routine is an analog of checkAndKillPutWindowBehind. It is more or less identical and you should keep them in synch.
' This version does NOT have calls to routines that require additional API calls
' I could have used compile time references (#) to bypass these but it seemed more appropriate to create
' separate copy for DockSettings and Enhance Icon Settings to run that it would not share with the other utilities.
'---------------------------------------------------------------------------------------
'
Public Function checkAndKill(ByRef NameProcess As String, ByVal checkForFolder As Boolean, ByVal confirmEachProcessKill As Boolean) As Boolean
' variables declared
Dim AppCount As Integer: AppCount = 0
Dim RProcessFound As Long: RProcessFound = 0
Dim SzExename As String: SzExename = vbNullString
Dim MyProcess As Long: MyProcess = 0
Dim i As Integer: i = 0
Dim binaryName As String: binaryName = vbNullString
Dim folderName As String: folderName = vbNullString
Dim procId As Long: procId = 0
Dim runningProcessFolder As String: runningProcessFolder = vbNullString
Dim processToKill As Long: processToKill = 0
Dim ExitCode As Long: ExitCode = 0
Dim thisHSnapshot As Long: thisHSnapshot = 0
Dim thisUProcess As PROCESSENTRY32
On Error GoTo checkAndKill_Error
'If debugFlg = 1 Then debugLog "%checkAndKill"
checkAndKill = False
MyProcess = GetCurrentProcessId()
If NameProcess <> vbNullString Then
AppCount = 0
binaryName = getFileNameFromPath(NameProcess)
If binaryName = vbNullString Then Exit Function ' catchall to prevent closure of unknown processes if the name is malformed
folderName = getFolderNameFromPath(NameProcess)
thisUProcess.dwSize = Len(thisUProcess)
thisHSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
'hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
RProcessFound = ProcessFirst(thisHSnapshot, thisUProcess)
Do
i = InStr(1, thisUProcess.szexeFile, Chr(0))
SzExename = LCase$(Left$(thisUProcess.szexeFile, i - 1))
'WinDirEnv = Environ("Windir") + "\"
'WinDirEnv = LCase$(WinDirEnv)
If Right$(SzExename, Len(binaryName)) = LCase$(binaryName) Then
AppCount = AppCount + 1
processToKill = OpenProcess(PROCESS_ALL_ACCESS, False, thisUProcess.th32ProcessID)
If thisUProcess.th32ProcessID = MyProcess Then
'MsgBox "hmmm" & MyProcess ' we never want to kill our own process...
Else
If checkForFolder = True Then ' only check the process actual run folder when killing an app from the dock
procId = thisUProcess.th32ProcessID ' actual PID
runningProcessFolder = getFolderNameFromPath(getExePathFromPID(procId))
If LCase$(runningProcessFolder) = LCase$(folderName) Then
' checkAndKill = TerminateProcess(processToKill, ExitCode)
' Call CloseHandle(processToKill)
checkAndKill = confirmEachKill(binaryName, procId, processToKill, confirmEachProcessKill, ExitCode)
End If
Else ' just go ahead and kill whatever process I say must go
' checkAndKill = TerminateProcess(processToKill, ExitCode)
' Call CloseHandle(processToKill)
checkAndKill = confirmEachKill(binaryName, procId, processToKill, confirmEachProcessKill, ExitCode)
End If
End If
End If
RProcessFound = ProcessNext(thisHSnapshot, thisUProcess)
Loop While RProcessFound
Call CloseHandle(thisHSnapshot)
End If
On Error GoTo 0
Exit Function
checkAndKill_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure checkAndKill of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : getExePathFromPID
' Author : beededea
' Date : 25/08/2020
' Purpose : getting the full path of a running process is not as easy as you'd expect
'---------------------------------------------------------------------------------------
'
Public Function getExePathFromPID(ByVal idProc As Long) As String
Dim sBuf As String: sBuf = vbNullString
Dim sChar As Long: sChar = 0
Dim useloop As Integer: useloop = 0
Dim hProcess As Long: hProcess = 0
On Error GoTo getExePathFromPID_Error
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, idProc)
If hProcess Then
sBuf = String$(260, vbNullChar)
sChar = GetProcessImageFileName(hProcess, sBuf, 260)
If sChar Then
sBuf = NoNulls(sBuf)
' this loop replaces the internal windows volume name with the legacy naming convention, ie. C:\, D:\ &c
For useloop = 1 To lstDevicesListCount
If InStr(1, sBuf, lstDevices(1, useloop)) > 0 Then
sBuf = Replace(sBuf, lstDevices(1, useloop), Chr$(lstDevices(0, useloop)) & ":")
Exit For
End If
Next useloop
getExePathFromPID = sBuf
End If
CloseHandle hProcess
End If
On Error GoTo 0
Exit Function
getExePathFromPID_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getExePathFromPID of Module common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : NoNulls
' Author : beededea
' Date : 25/08/2020
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function NoNulls(ByVal Strng As String) As String
Dim i As Integer: i = 0
On Error GoTo NoNulls_Error
If Len(Strng) > 0 Then
i = InStr(Strng, vbNullChar)
Select Case i
Case 0
NoNulls = Strng
Case 1
NoNulls = vbNullString
Case Else
NoNulls = Left$(Strng, i - 1)
End Select
End If
On Error GoTo 0
Exit Function
NoNulls_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure NoNulls of Module common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : Is64bit
' Author : Spider Harper
' Date : 04/07/2020
' Purpose : is this program running on a 64bit system or not?
'---------------------------------------------------------------------------------------
'
Public Function Is64bit() As Boolean
' variables declared
Dim handle As Long: handle = 0
Dim bolFunc As Boolean: bolFunc = False
' Assume initially that this is not a Wow64 process
On Error GoTo Is64bit_Error
bolFunc = False
' Now check to see if IsWow64Process function exists
handle = GetProcAddress(GetModuleHandle("kernel32"), _
"IsWow64Process")
If handle > 0 Then ' IsWow64Process function exists
' Now use the function to determine if
' we are running under Wow64
IsWow64Process GetCurrentProcess(), bolFunc
End If
Is64bit = bolFunc
On Error GoTo 0
Exit Function
Is64bit_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Is64bit of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : ExtractSuffix
' Author : beededea
' Date : 20/06/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function ExtractSuffix(ByVal strPath As String) As String
' variables declared
Dim AY() As String ' string array
Dim Max As Integer: Max = 0
On Error GoTo ExtractSuffix_Error
'If debugFlg = 1 Then debugLog "%" & "ExtractSuffix"
If strPath = vbNullString Then
ExtractSuffix = vbNullString
Exit Function
End If
If InStr(strPath, ".") <> 0 Then
AY = Split(strPath, ".")
Max = UBound(AY)
ExtractSuffix = AY(Max)
Else
ExtractSuffix = ""
End If
On Error GoTo 0
Exit Function
ExtractSuffix_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExtractSuffix of Module Common"
End Function
'---------------------------------------------------------------------------------------
' Procedure : getFolderNameFromPath
' Author : beededea
' Date : 11/07/2019
' Purpose : get the folder or directory path as a string not including the last backslash
'---------------------------------------------------------------------------------------
'
Public Function getFolderNameFromPath(ByRef Path As String) As String
On Error GoTo getFolderNameFromPath_Error
'If debugFlg = 1 Then debugLog "%" & "getFolderNameFromPath"
If InStrRev(Path, "\") = 0 Then
getFolderNameFromPath = vbNullString
Exit Function
End If
getFolderNameFromPath = Left$(Path, InStrRev(Path, "\") - 1)
On Error GoTo 0
Exit Function
getFolderNameFromPath_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getFolderNameFromPath of Module Common"
End Function