-
Notifications
You must be signed in to change notification settings - Fork 2
/
ucDriveCombo.twin
1523 lines (1421 loc) · 66.1 KB
/
ucDriveCombo.twin
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
[FormDesignerId("524713C4-CB98-45C0-85ED-B7BA1554E6B2")]
[ClassId("66316E7A-F813-4AF1-963F-AB17D7717B98")]
[InterfaceId("E976AE80-AEB1-463E-B03B-5E34EF35C02D")]
[EventInterfaceId("BC6DD870-297E-4986-AB5C-BCDFFE6522CC")]
[COMControl]
[Description("ucDriveCombo - Modern DriveList Replacement")]
Class ucDriveCombo
Option Explicit
'********************************************************************
' ucDriveCombo v1.6
' A Modern DriveList Replacement
' by Jon Johnson
'
' Provides a modernized option for a Drive Combo without the extra
' complexity of a full blown ucShellBrowse control.
'
' Requirements: VB6 or twinBASIC Beta 515
' Note: This file combines the mUCDCHelper module; in VB6 that
' must be in its own .bas.
'
' Features:
' -Same codebase for VB6 and twinBASIC
' -64bit compatible
' -Filter drives shown by type
' -Uses same friendly name and icon as Explorer
' -Monitors for drive add/remove (optional)
' -Supports both dropdown list and standard dropdown styles
' -Drive selection can be get/set by path, letter, or name.
' -SelectionChanged event
' -Can provide list of drives
' -Can optionally classify USB hard drives as removable.
'
' Changelog:
' Version 1.6 (Released 19 May 2024)
' -Added ShowHiddenDrives option, default false, to show/hide
' drives that are hidden from the user in Explorer.
' -Changed default BackColor to standard CB's white.
'
' Version 1.5 (Released 27 Apr 2024)
' -(Bug fix) NoFixedUSB option not working
' -(Bug fix) Drive type always reported as 0
'
' Version 1.4 (Released 25 Apr 2024)
' -The .Drive legacy method now returns the same path for
' mapped network drives.
' -There's now a drive icon and control name/version in the
' combobox during design mode instead of a generic combo.
'
' Version 1.3 (Released 23 Apr 2024)
' -The .Drive property now returns names identical to the legacy
' DriveList control, and when set, behaves identical to that
' as well, only comparing the first letter.
' -(Bug fix) ShowRemovableDrives toggled network drives instead.
'
' Version 1.2 (Released 22 Apr 2024)
' -Add Drive property get/let for compatibility with DriveList;
' it behaves identically to .SelectDriveName.
' -DriveCount is now ListCount, for DriveList compat. Also added
' .ListIndex for selected index, and .List, same as GetDriveName.
' -Add Enabled property get/let.
' -(Bug fix) FocusDriveList VB6 syntax error
' -(Bug fix) VB6 control bottom cut off
'
' Version 1.1 (Released 22 Apr 2024)
' -Autosize UC height to combo height
' -Custom drop width now DPI aware
' -FocusDriveList method to hopefully partially defray the lack of
' a massive and usually typelib dependent in-place activation
' hook to handle tab properly. Recommend ucShellBrowse if you
' need proper tab key support.
' -(Bug fix) DPI variable overridden by old test line.
'
' Version 1.0 (Released 22 Apr 2024)
' -Add Property Lets for SelectedDrive_____
' -Add device add/remove monitoring via RegisterDeviceNotification
' -Add DPI aware support
' -Add DropdownWidth option
'
'********************************************************************
Private Enum BOOL
CFALSE
CTRUE
End Enum
Private Const WC_COMBOBOXEX = "ComboBoxEx32"
#If TWINBASIC Then
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function CreateFileW Lib "kernel32" (ByVal lpFileName As LongPtr, ByVal dwDesiredAccess As Long, ByVal dwShareMode As FileShareMode, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As CreateFileDisposition, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr
Private Declare PtrSafe Function DeviceIoControl Lib "kernel32" (ByVal hDevice As LongPtr, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As BOOL
Private Declare PtrSafe Function SHGetFileInfoW Lib "shell32" (ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFOW, ByVal cbFileInfo As Long, ByVal uFlags As SHGFI_flags) As LongPtr
Private Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As RECT) As BOOL
Private Declare PtrSafe Function GetLogicalDriveStringsW Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As LongPtr) As Long
Private Declare PtrSafe Function GetDriveTypeW Lib "kernel32" (Optional ByVal lpRootPathName As LongPtr) As DriveTypes
Private Declare PtrSafe Function SHParseDisplayName Lib "shell32" (ByVal pszName As LongPtr, ByVal pbc As LongPtr, ByRef ppidl As LongPtr, ByVal sfgaoIn As Long, ByRef psfgaoOut As Long) As Long
Private Declare PtrSafe Function SHGetNameFromIDList Lib "shell32" (ByVal pidl As LongPtr, ByVal sigdnName As SIGDN, ByRef ppszName As LongPtr) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hWnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal CX As Long, ByVal CY As Long, ByVal wFlags As SWP_Flags) As Long
Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As LongPtr) As BOOL
Private Declare PtrSafe Function GetWindowsDirectoryW Lib "kernel32" (ByVal lpBuffer As LongPtr, ByVal nSize As Long) As Long
Private Declare PtrSafe Function CreateWindowExW Lib "user32" (ByVal dwExStyle As Long, ByVal lpClassName As LongPtr, ByVal lpWindowName As LongPtr, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As LongPtr, ByVal hMenu As LongPtr, ByVal hInstance As LongPtr, lpParam As Any) As LongPtr
Private Declare PtrSafe Function SysReAllocStringW Lib "oleaut32" Alias "SysReAllocString" (ByVal pBSTR As LongPtr, Optional ByVal pszStrPtr As LongPtr) As Long
Private Declare PtrSafe Sub CoTaskMemFree Lib "ole32" (ByVal pv As LongPtr)
Private Declare PtrSafe Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As LongPtr, ByVal uMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare PtrSafe Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As LongPtr, ByVal pfnSubclass As LongPtr, ByVal uIdSubclass As LongPtr, Optional ByVal dwRefData As LongPtr) As Long
Private Declare PtrSafe Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As LongPtr, ByVal pfnSubclass As LongPtr, ByVal uIdSubclass As LongPtr) As Long
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hDC As LongPtr) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function RegisterDeviceNotification Lib "user32" Alias "RegisterDeviceNotificationW" (ByVal hRecipient As LongPtr, NotificationFilter As Any, ByVal Flags As DEVICE_NOTIFY_FLAGS) As LongPtr
Private Declare PtrSafe Function UnregisterDeviceNotification Lib "user32" (ByVal Handle As LongPtr) As BOOL
Private Declare PtrSafe Function DestroyWindow Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function MoveWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare PtrSafe Function EnableWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal fEnable As BOOL) As BOOL
Private Declare PtrSafe Function RedrawWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal lprcUpdate As LongPtr, ByVal hrgnUpdate As LongPtr, ByVal fuRedraw As Long) As Long
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr, ByRef lpRect As RECT) As Long
Private Declare PtrSafe Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function GetVolumeInformationW Lib "kernel32" (ByVal lpRootPathName As LongPtr, ByVal lpVolumeNameBuffer As LongPtr, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As LongPtr, ByVal nFileSystemNameSize As Long) As BOOL
Private Declare PtrSafe Function PathIsNetworkPathW Lib "shlwapi.dll" (ByVal lpszPath As LongPtr) As BOOL
Private Declare PtrSafe Function PathIsUNCW Lib "shlwapi.dll" (ByVal lpszPath As LongPtr) As BOOL
Private Declare PtrSafe Function WNetGetUniversalNameW Lib "mpr.dll" (ByVal lpLocalPath As LongPtr, ByVal dwInfoLevel As NETWK_NAME_INFOLEVEL, lpBuffer As Any, lpBufferSize As Long) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Private Declare PtrSafe Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare PtrSafe Function RegOpenKeyExW Lib "advapi32" ([TypeHint(RegKeyspace)] ByVal hKey As LongPtr, ByVal lpSubKey As LongPtr, ByVal ulOptions As RegOptions, ByVal samDesired As REGSAM, phkResult As LongPtr) As Long
Private DeclareWide PtrSafe Function RegQueryValueExW Lib "advapi32" ([TypeHint(RegKeyspace)] ByVal hKey As LongPtr, ByVal lpValueName As LongPtr, ByVal lpReserved As LongPtr, lpType As REGTYPES, lpData As Any, lpcbData As Long) As Long
Private Declare PtrSafe Function RegCloseKey Lib "advapi32" ([TypeHint(RegKeyspace)] ByVal hKey As LongPtr) As Long
#Else
Private Enum LongPtr
vbNullPtr
End Enum
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare Function CreateFileW Lib "kernel32" (ByVal lpFileName As LongPtr, ByVal dwDesiredAccess As Long, ByVal dwShareMode As FileShareMode, ByVal lpSecurityAttributes As LongPtr, ByVal dwCreationDisposition As CreateFileDisposition, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As LongPtr, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As LongPtr) As BOOL
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As RECT) As BOOL
Private Declare Function SHGetFileInfoW Lib "shell32" (ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFOW, ByVal cbFileInfo As Long, ByVal uFlags As SHGFI_flags) As LongPtr
Private Declare Function GetLogicalDriveStringsW Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As LongPtr) As Long
Private Declare Function GetDriveTypeW Lib "kernel32" (Optional ByVal lpRootPathName As LongPtr) As DriveTypes
Private Declare Function SHParseDisplayName Lib "shell32" (ByVal pszName As LongPtr, ByVal pbc As LongPtr, ByRef ppidl As LongPtr, ByVal sfgaoIn As Long, ByRef psfgaoOut As Long) As Long
Private Declare Function SHGetNameFromIDList Lib "shell32" (ByVal pidl As LongPtr, ByVal sigdnName As SIGDN, ByRef ppszName As LongPtr) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal CX As Long, ByVal CY As Long, ByVal wFlags As SWP_Flags) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As LongPtr) As BOOL
Private Declare Function GetWindowsDirectoryW Lib "kernel32" (ByVal lpBuffer As LongPtr, ByVal nSize As Long) As Long
Private Declare Function CreateWindowExW Lib "user32" (ByVal dwExStyle As Long, ByVal lpClassName As LongPtr, ByVal lpWindowName As LongPtr, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As LongPtr, ByVal hMenu As LongPtr, ByVal hInstance As LongPtr, lpParam As Any) As LongPtr
Private Declare Function SysReAllocStringW Lib "oleaut32" Alias "SysReAllocString" (ByVal pBSTR As LongPtr, Optional ByVal pszStrPtr As LongPtr) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As LongPtr)
Private Declare Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As LongPtr, ByVal uMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As LongPtr, ByVal pfnSubclass As LongPtr, ByVal uIdSubclass As LongPtr, Optional ByVal dwRefData As LongPtr) As Long
Private Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As LongPtr, ByVal pfnSubclass As LongPtr, ByVal uIdSubclass As LongPtr) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hDC As LongPtr) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long
Private Declare Function RegisterDeviceNotification Lib "user32" Alias "RegisterDeviceNotificationW" (ByVal hRecipient As LongPtr, NotificationFilter As Any, ByVal Flags As DEVICE_NOTIFY_FLAGS) As LongPtr
Private Declare Function UnregisterDeviceNotification Lib "user32" (ByVal Handle As LongPtr) As BOOL
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal fEnable As BOOL) As BOOL
Private Declare Function RedrawWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal lprcUpdate As LongPtr, ByVal hrgnUpdate As LongPtr, ByVal fuRedraw As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr, ByRef lpRect As RECT) As Long
Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hWnd As LongPtr) As LongPtr
Private Declare Function GetVolumeInformationW Lib "kernel32" (ByVal lpRootPathName As LongPtr, ByVal lpVolumeNameBuffer As LongPtr, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As LongPtr, ByVal nFileSystemNameSize As Long) As BOOL
Private Declare Function PathIsNetworkPathW Lib "shlwapi.dll" (ByVal lpszPath As LongPtr) As BOOL
Private Declare Function PathIsUNCW Lib "shlwapi.dll" (ByVal lpszPath As LongPtr) As BOOL
Private Declare Function WNetGetUniversalNameW Lib "mpr.dll" (ByVal lpLocalPath As LongPtr, ByVal dwInfoLevel As NETWK_NAME_INFOLEVEL, lpBuffer As Any, lpBufferSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare Function RegOpenKeyExW Lib "advapi32" (ByVal hKey As LongPtr, ByVal lpSubKey As LongPtr, ByVal ulOptions As RegOptions, ByVal samDesired As REGSAM, phkResult As LongPtr) As Long
Private Declare Function RegQueryValueExW Lib "advapi32" (ByVal hKey As LongPtr, ByVal lpValueName As LongPtr, ByVal lpReserved As LongPtr, lpType As REGTYPES, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As LongPtr) As Long
#End If
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WS_TABSTOP = &H00010000
Private Const INVALID_HANDLE_VALUE = -1&
Private Const S_OK = 0
Private Const MAX_PATH As Long = 260
Private Const EM_SETREADONLY = &HCF
Private Const WM_DESTROY = &H0002
Private Const WM_NOTIFYFORMAT = &H0055
Private Const WM_COMMAND = &H0111
Private Const WM_DEVICECHANGE = &H0219
Private Const NFR_UNICODE = 2
Private Const LOGPIXELSY = 90
Private Const ERROR_SUCCESS As Long = 0
Public Enum REGTYPES
REG_NONE = 0
REG_SZ = 1
REG_EXPAND_SZ = 2
REG_BINARY = 3
REG_DWORD = 4
REG_DWORD_BIG_ENDIAN = 5
REG_DWORD_LITTLE_ENDIAN = 4
REG_LINK = 6
REG_MULTI_SZ = 7
REG_RESOURCE_LIST = 8
REG_FULL_RESOURCE_DESCRIPTOR = 9
REG_RESOURCE_REQUIREMENTS_LIST = &HA
REG_QWORD = &HB
REG_QWORD_LITTLE_ENDIAN = &HB
End Enum
Public Enum StandardAccessTypes
DELETE = (&H00010000)
READ_CONTROL = (&H00020000)
WRITE_DAC = (&H00040000)
WRITE_OWNER = (&H00080000)
SYNCHRONIZE = (&H00100000)
STANDARD_RIGHTS_REQUIRED = (&H000F0000)
STANDARD_RIGHTS_READ = (READ_CONTROL)
STANDARD_RIGHTS_WRITE = (READ_CONTROL)
STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
STANDARD_RIGHTS_ALL = (&H001F0000)
SPECIFIC_RIGHTS_ALL = (&H0000FFFF&)
' //
' // AccessSystemAcl access type
' //
ACCESS_SYSTEM_SECURITY = (&H01000000)
MAXIMUM_ALLOWED = (&H02000000)
End Enum
Public Enum REGSAM
KEY_QUERY_VALUE = (&H0001)
KEY_SET_VALUE = (&H0002)
KEY_CREATE_SUB_KEY = (&H0004)
KEY_ENUMERATE_SUB_KEYS = (&H0008)
KEY_NOTIFY = (&H0010)
KEY_CREATE_LINK = (&H0020)
KEY_WOW64_32KEY = (&H0200)
KEY_WOW64_64KEY = (&H0100)
KEY_WOW64_RES = (&H0300)
KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
End Enum
Public Enum RegOptions
REG_OPTION_RESERVED = (&H00000000) ' Parameter is reserved
REG_OPTION_NON_VOLATILE = (&H00000000) ' Key is preserved when system is rebooted
REG_OPTION_VOLATILE = (&H00000001) ' Key is not preserved when system is rebooted
REG_OPTION_CREATE_LINK = (&H00000002) ' Created key is a symbolic link
REG_OPTION_BACKUP_RESTORE = (&H00000004) ' open for backup or restore special access rules privilege required
REG_OPTION_OPEN_LINK = (&H00000008) ' Open symbolic link
REG_OPTION_DONT_VIRTUALIZE = (&H00000010) ' Disable Open/Read/Write virtualization for this open and the resulting handle.
REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE Or REG_OPTION_OPEN_LINK Or REG_OPTION_DONT_VIRTUALIZE)
REG_OPEN_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_BACKUP_RESTORE Or REG_OPTION_OPEN_LINK Or REG_OPTION_DONT_VIRTUALIZE)
End Enum
Public Enum RegKeyspace
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_PERFORMANCE_TEXT = &H80000050
HKEY_PERFORMANCE_NLSTEXT = &H80000060
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
HKEY_CURRENT_USER_LOCAL_SETTINGS = &H80000007
End Enum
Private Enum NETWK_NAME_INFOLEVEL
UNIVERSAL_NAME_INFO_LEVEL = &H00000001
REMOTE_NAME_INFO_LEVEL = &H00000002
End Enum
Private Type UNIVERSAL_NAME_INFOW
lpUniversalName As LongPtr
End Type
Private Enum FileShareMode
FILE_SHARE_READ = &H00000001
FILE_SHARE_WRITE = &H00000002
FILE_SHARE_DELETE = &H00000004
End Enum
Private Enum CreateFileDisposition
CREATE_NEW = 1
CREATE_ALWAYS = 2
OPEN_EXISTING = 3
OPEN_ALWAYS = 4
TRUNCATE_EXISTING = 5
End Enum
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As LongPtr
bInheritHandle As Long
End Type
Private Type OVERLAPPED
Internal As LongPtr
InternalHigh As LongPtr
#If Win64 Then
OffsetsOrPtr As LongLong
#Else
OffsetOrPtr As Long
OffsetHigh As Long
#End If
hEvent As LongPtr
End Type
Private Enum SIGDN
SIGDN_NORMALDISPLAY = &H00000000
SIGDN_PARENTRELATIVEPARSING = &H80018001
SIGDN_DESKTOPABSOLUTEPARSING = &H80028000
SIGDN_PARENTRELATIVEEDITING = &H80031001
SIGDN_DESKTOPABSOLUTEEDITING = &H8004c000
SIGDN_FILESYSPATH = &H80058000
SIGDN_URL = &H80068000
SIGDN_PARENTRELATIVEFORADDRESSBAR = &H8007c001
SIGDN_PARENTRELATIVE = &H80080001
SIGDN_PARENTRELATIVEFORUI = &H80094001
End Enum
Private Enum DriveTypes
DRIVE_UNKNOWN
DRIVE_NO_ROOT_DIR
DRIVE_REMOVABLE
DRIVE_FIXED
DRIVE_REMOTE
DRIVE_CDROM
DRIVE_RAMDISK
End Enum
Private Const IOCTL_STORAGE_GET_HOTPLUG_INFO As Long = &H2D0C14
Private Type STORAGE_HOTPLUG_INFO
Size As Long ' version
MediaRemovable As Byte ' ie. zip, jaz, cdrom, mo, etc. vs hdd
MediaHotplug As Byte ' ie. does the device succeed a lock even though its not lockable media?
DeviceHotplug As Byte ' ie. 1394, USB, etc.
WriteCacheEnableOverride As Byte ' This field should not be relied upon because it is no longer used
End Type
Private Type SHFILEINFOW ' shfi
hIcon As LongPtr
iIcon As Long
dwAttributes As Long
szDisplayName(MAX_PATH - 1) As Integer
szTypeName(79) As Integer
End Type
Private Enum SHGFI_flags
SHGFI_LARGEICON = &H0 ' sfi.hIcon is large icon
SHGFI_SMALLICON = &H1 ' sfi.hIcon is small icon
SHGFI_OPENICON = &H2 ' sfi.hIcon is open icon
SHGFI_SHELLICONSIZE = &H4 ' sfi.hIcon is shell size (not system size), rtns BOOL
SHGFI_PIDL = &H8 ' pszPath is pidl, rtns BOOL
' Indicates that the function should not attempt to access the file specified by pszPath.
' Rather, it should act as if the file specified by pszPath exists with the file attributes
' passed in dwFileAttributes. This flag cannot be combined with the SHGFI_ATTRIBUTES,
' SHGFI_EXETYPE, or SHGFI_PIDL flags <---- !!!
SHGFI_USEFILEATTRIBUTES = &H10 ' pretend pszPath exists, rtns BOOL
SHGFI_ADDOVERLAYS = &H20
SHGFI_OVERLAYINDEX = &H40 'Return overlay index in upper 8 bits of iIcon.
SHGFI_ICON = &H100 ' fills sfi.hIcon, rtns BOOL, use DestroyIcon
SHGFI_DISPLAYNAME = &H200 ' isf.szDisplayName is filled (SHGDN_NORMAL), rtns BOOL
SHGFI_TYPENAME = &H400 ' isf.szTypeName is filled, rtns BOOL
SHGFI_ATTRIBUTES = &H800 ' rtns IShellFolder::GetAttributesOf SFGAO_* flags
SHGFI_ICONLOCATION = &H1000 ' fills sfi.szDisplayName with filename
' containing the icon, rtns BOOL
SHGFI_EXETYPE = &H2000 ' rtns two ASCII chars of exe type
SHGFI_SYSICONINDEX = &H4000 ' sfi.iIcon is sys il icon index, rtns hImagelist
SHGFI_LINKOVERLAY = &H8000& ' add shortcut overlay to sfi.hIcon
SHGFI_SELECTED = &H10000 ' sfi.hIcon is selected icon
SHGFI_ATTR_SPECIFIED = &H20000 ' get only attributes specified in sfi.dwAttributes
End Enum
Private Enum DEVICE_NOTIFY_FLAGS
DEVICE_NOTIFY_WINDOW_HANDLE = &H00000000
DEVICE_NOTIFY_SERVICE_HANDLE = &H00000001
DEVICE_NOTIFY_CALLBACK = &H00000002
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = &H00000004
End Enum
Private Enum WMDEVICECHANGE_wParam
DBT_APPYBEGIN = &H0000
DBT_APPYEND = &H0001
DBT_DEVNODES_CHANGED = &H0007
DBT_QUERYCHANGECONFIG = &H0017
DBT_CONFIGCHANGED = &H0018
DBT_CONFIGCHANGECANCELED = &H0019
DBT_MONITORCHANGE = &H001B
DBT_SHELLLOGGEDON = &H0020
DBT_CONFIGMGAPI32 = &H0022
DBT_VXDINITCOMPLETE = &H0023
DBT_VOLLOCKQUERYLOCK = &H8041&
DBT_VOLLOCKLOCKTAKEN = &H8042&
DBT_VOLLOCKLOCKFAILED = &H8043&
DBT_VOLLOCKQUERYUNLOCK = &H8044&
DBT_VOLLOCKLOCKRELEASED = &H8045&
DBT_VOLLOCKUNLOCKFAILED = &H8046&
DBT_NO_DISK_SPACE = &H0047
DBT_LOW_DISK_SPACE = &H0048
DBT_CONFIGMGPRIVATE = &H7FFF
DBT_DEVICEARRIVAL = &H8000& ' system detected a new device
DBT_DEVICEQUERYREMOVE = &H8001& ' wants to remove, may fail
DBT_DEVICEQUERYREMOVEFAILED = &H8002& ' removal aborted
DBT_DEVICEREMOVEPENDING = &H8003& ' about to remove, still avail.
DBT_DEVICEREMOVECOMPLETE = &H8004& ' device is gone
DBT_DEVICETYPESPECIFIC = &H8005& ' type specific event
DBT_CUSTOMEVENT = &H8006& ' user-defined event
DBT_VPOWERDAPI = &H8100& ' VPOWERD API for Win95
DBT_USERDEFINED = &HFFFF&
End Enum
Private Enum DBT_Flags
DBTF_RESOURCE = &H00000001 ' network resource
DBTF_XPORT = &H00000002 ' new transport coming or going
DBTF_SLOWNET = &H00000004 ' new incoming transport is slow
' (dbcn_resource undefined for now)
End Enum
Private Enum DBT_DEVTYPE
DBT_DEVTYP_OEM = &H00000000 ' oem-defined device type
DBT_DEVTYP_DEVNODE = &H00000001 ' devnode number
DBT_DEVTYP_VOLUME = &H00000002 ' logical volume
DBT_DEVTYP_PORT = &H00000003 ' serial, parallel
DBT_DEVTYP_NET = &H00000004 ' network resource
DBT_DEVTYP_DEVICEINTERFACE = &H00000005 ' device interface class
DBT_DEVTYP_HANDLE = &H00000006 ' file system handle
End Enum
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type DEV_BROADCAST_DEVICEINTERFACE
dbcc_size As Long
dbcc_devicetype As DBT_DEVTYPE
dbcc_reserved As Long
dbcc_classguid As UUID
dbcc_name (0 To (MAX_PATH - 1)) As Integer 'NOTE: Buffer ubound is a guess. You may need more. It's a variable C-style array.
End Type
Private Enum SWP_Flags
SWP_NOSIZE = &H1
SWP_NOMOVE = &H2
SWP_NOZORDER = &H4
SWP_NOREDRAW = &H8
SWP_NOACTIVATE = &H10
SWP_FRAMECHANGED = &H20
SWP_DRAWFRAME = SWP_FRAMECHANGED
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_NOCOPYBITS = &H100
SWP_NOOWNERZORDER = &H200
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSENDCHANGING = &H400
SWP_DEFERERASE = &H2000
SWP_ASYNCWINDOWPOS = &H4000
End Enum
Private Const CCM_FIRST = &H2000
Private Const CCM_SETBKCOLOR = (CCM_FIRST + 1) ' lParam is bkColor
Private Const CCM_SETCOLORSCHEME = (CCM_FIRST + 2) ' lParam is color scheme
Private Const CCM_GETCOLORSCHEME = (CCM_FIRST + 3) ' fills in COLORSCHEME pointed to by lParam
Private Const CCM_GETDROPTARGET = (CCM_FIRST + 4)
Private Const CCM_SETUNICODEFORMAT = (CCM_FIRST + 5)
Private Const CCM_GETUNICODEFORMAT = (CCM_FIRST + 6)
Private Const CCM_SETVERSION = (CCM_FIRST + 7)
Private Const CCM_GETVERSION = (CCM_FIRST + 8)
Private Const CCM_SETNOTIFYWINDOW = (CCM_FIRST + 9) '// wParam == hwndParent.
Private Const CCM_SETWINDOWTHEME = (CCM_FIRST + 11)
Private Const CCM_DPISCALE = (CCM_FIRST + 12)
Private Const CCM_TRANSLATEACCELERATOR = &H461 '(WM_USER + 97)
Private Const WM_USER = &H0400
Private Const CB_ADDSTRING = &H143
Private Const CB_DELETESTRING = &H144
Private Const CB_DIR = &H145
Private Const CB_FINDSTRING = &H14C
Private Const CB_FINDSTRINGEXACT = &H158
Private Const CB_GETCOMBOBOXINFO = &H164
Private Const CB_GETCOUNT = &H146
Private Const CB_GETCURSEL = &H147
Private Const CB_GETDROPPEDCONTROLRECT = &H152
Private Const CB_GETDROPPEDSTATE = &H157
Private Const CB_GETDROPPEDWIDTH = &H15F
Private Const CB_GETEDITSEL = &H140
Private Const CB_GETEXTENDEDUI = &H156
Private Const CB_GETHORIZONTALEXTENT = &H15D
Private Const CB_GETITEMDATA = &H150
Private Const CB_GETITEMHEIGHT = &H154
Private Const CB_GETLBTEXT = &H148
Private Const CB_GETLBTEXTLEN = &H149
Private Const CB_GETLOCALE = &H15A
Private Const CB_GETTOPINDEX = &H15B
Private Const CB_INITSTORAGE = &H161
Private Const CB_INSERTSTRING = &H14A
Private Const CB_LIMITTEXT = &H141
Private Const CB_MSGMAX = &H15B
Private Const CB_MULTIPLEADDSTRING = &H163
Private Const CB_RESETCONTENT = &H14B
Private Const CB_SELECTSTRING = &H14D
Private Const CB_SETCURSEL = &H14E
Private Const CB_SETDROPPEDWIDTH = &H160
Private Const CB_SETEDITSEL = &H142
Private Const CB_SETEXTENDEDUI = &H155
Private Const CB_SETHORIZONTALEXTENT = &H15E
Private Const CB_SETITEMDATA = &H151
Private Const CB_SETITEMHEIGHT = &H153
Private Const CB_SETLOCALE = &H159
Private Const CB_SETTOPINDEX = &H15C
Private Const CB_SHOWDROPDOWN = &H14F
Private Const CBEC_SETCOMBOFOCUS = (&H165 + 1) ' ;internal_nt
Private Const CBEC_KILLCOMBOFOCUS = (&H165 + 2) ';internal_nt
Private Const CBM_FIRST As Long = &H1700&
Private Const CB_SETMINVISIBLE = (CBM_FIRST + 1)
Private Const CB_GETMINVISIBLE = (CBM_FIRST + 2)
Private Const CB_SETCUEBANNER = (CBM_FIRST + 3)
Private Const CB_GETCUEBANNER = (CBM_FIRST + 4)
Private Const CBEM_INSERTITEMA = (WM_USER + 1)
Private Const CBEM_SETIMAGELIST = (WM_USER + 2)
Private Const CBEM_GETIMAGELIST = (WM_USER + 3)
Private Const CBEM_GETITEMA = (WM_USER + 4)
Private Const CBEM_SETITEMA = (WM_USER + 5)
Private Const CBEM_DELETEITEM = CB_DELETESTRING
Private Const CBEM_GETCOMBOCONTROL = (WM_USER + 6)
Private Const CBEM_GETEDITCONTROL = (WM_USER + 7)
Private Const CBEM_SETEXTENDEDSTYLE = (WM_USER + 8)
Private Const CBEM_GETEXTENDEDSTYLE = (WM_USER + 9)
Private Const CBEM_HASEDITCHANGED = (WM_USER + 10)
Private Const CBEM_INSERTITEMW = (WM_USER + 11)
Private Const CBEM_SETITEMW = (WM_USER + 12)
Private Const CBEM_GETITEMW = (WM_USER + 13)
Private Const CBEM_INSERTITEM = CBEM_INSERTITEMW
Private Const CBEM_SETITEM = CBEM_SETITEMW
Private Const CBEM_GETITEM = CBEM_GETITEMW
Private Const CBEM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT '8192 + 5
Private Const CBEM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT '8192 + 6
Private Const CBEM_SETWINDOWTHEME = CCM_SETWINDOWTHEME '8192 + 11
Private Enum ComboBox_Styles
CBS_SIMPLE = &H1&
CBS_DROPDOWN = &H2&
CBS_DROPDOWNLIST = &H3&
CBS_OWNERDRAWFIXED = &H10&
CBS_OWNERDRAWVARIABLE = &H20&
CBS_AUTOHSCROLL = &H40
CBS_OEMCONVERT = &H80
CBS_SORT = &H100&
CBS_HASSTRINGS = &H200&
CBS_NOINTEGRALHEIGHT = &H400&
CBS_DISABLENOSCROLL = &H800&
CBS_UPPERCASE = &H2000
CBS_LOWERCASE = &H4000
End Enum
'// Notification messages
Private Const H_MAX As Long = (&HFFFF + 1)
Private Const CBN_ERRSPACE = (-1)
Private Const CBN_SELCHANGE = 1
Private Const CBN_DBLCLK = 2
Private Const CBN_SETFOCUS = 3
Private Const CBN_KILLFOCUS = 4
Private Const CBN_EDITCHANGE = 5
Private Const CBN_EDITUPDATE = 6
Private Const CBN_DROPDOWN = 7
Private Const CBN_CLOSEUP = 8
Private Const CBN_SELENDOK = 9
Private Const CBN_SELENDCANCEL = 10
Private Const CBEN_FIRST = (H_MAX - 800&)
Private Const CBEN_LAST = (H_MAX - 830&)
Private Const CBEN_GETDISPINFOA = (CBEN_FIRST - 0)
Private Const CBEN_GETDISPINFOW = (CBEN_FIRST - 7)
Private Const CBEN_GETDISPINFO = CBEN_GETDISPINFOW
Private Const CBEN_INSERTITEM = (CBEN_FIRST - 1)
Private Const CBEN_DELETEITEM = (CBEN_FIRST - 2)
Private Const CBEN_BEGINEDIT = (CBEN_FIRST - 4)
Private Const CBEN_ENDEDITA = (CBEN_FIRST - 5)
Private Const CBEN_ENDEDITW = (CBEN_FIRST - 6)
Private Const CBEN_ENDEDIT = CBEN_ENDEDITW
Private Const CBEN_DRAGBEGINA = (CBEN_FIRST - 8)
Private Const CBEN_DRAGBEGINW = (CBEN_FIRST - 9)
Private Const CBEN_DRAGBEGIN = CBEN_DRAGBEGINW
'// lParam specifies why the endedit is happening
Private Const CBENF_KILLFOCUS = 1
Private Const CBENF_RETURN = 2
Private Const CBENF_ESCAPE = 3
Private Const CBENF_DROPDOWN = 4
Private Enum CBEX_ExStyles
CBES_EX_NOEDITIMAGE = &H1
CBES_EX_NOEDITIMAGEINDENT = &H2
CBES_EX_PATHWORDBREAKPROC = &H4
CBES_EX_NOSIZELIMIT = &H8
CBES_EX_CASESENSITIVE = &H10
'6.0
CBES_EX_TEXTENDELLIPSIS = &H20
End Enum
Private Enum COMBOBOXEXITEM_Mask
CBEIF_TEXT = &H1
CBEIF_IMAGE = &H2
CBEIF_SELECTEDIMAGE = &H4
CBEIF_OVERLAY = &H8
CBEIF_INDENT = &H10
CBEIF_LPARAM = &H20
CBEIF_DI_SETITEM = &H10000000
End Enum
Private Type COMBOBOXEXITEMW
Mask As COMBOBOXEXITEM_Mask
iItem As LongPtr
pszText As LongPtr '// LPCSTR
cchTextMax As Long
iImage As Long
iSelectedImage As Long
iOverlay As Long
iIndent As Long
lParam As LongPtr
End Type
Private hMain As LongPtr
Private hCB As LongPtr
Private hEdit As LongPtr
Private himl As LongPtr
Private hNotify As LongPtr
Private mDPI As Single
Private mStd As Boolean
Private Const mDefStd As Boolean = True
Private mOpt As Boolean
Private Const mDefOpt As Boolean = True
Private mNet As Boolean
Private Const mDefNet As Boolean = True
Private mUSB As Boolean
Private Const mDefUSB As Boolean = True
Private mHP As Boolean
Private Const mDefHP As Boolean = False
Private cyList As Long
Private Const mDefCY As Long = 400
Private cxList As Long
Private Const mDefCX As Long = 0
Private mDD As Boolean
Private Const mDefDD As Boolean = True
Private mBk As OLE_COLOR
Private Const mDefBk As Long = &HFFFFFF
Private mNotify As Boolean
Private Const mDefNotify As Boolean = True
Private mEnabled As Boolean
Private Const mDefEnabled As Boolean = True
Private mShowHidden As Boolean
Private Const mDefShowHidden As Boolean = False
#If TWINBASIC Then
[EnumId("55209AC8-57EA-4644-AA85-4974AA31E100")]
#End If
Public Enum UCDCType
UCDC_DropdownList
UCDC_Combo
End Enum
Private mStyle As UCDCType
Private Const mDefStyle As Long = 0
'bControlInit = The DriveAdded event is being raised as the control starts up and adds all drives,
' it's not representing a new drive added to the system.
'Add/Remove events are only raised if MonitorChanges = True (including on startup).
Public Event DriveAdded(ByVal Path As String, ByVal Letter As String, ByVal Name As String, ByVal nType As Long, ByVal bControlInit As Boolean)
Public Event DriveRemoved(ByVal Path As String, ByVal Letter As String, ByVal Name As String, ByVal nType As Long)
Public Event SelectionChanged(ByVal NewPath As String, ByVal NewLetter As String, ByVal NewName As String, ByVal NewDriveType As Long)
Attribute SelectionChanged.VB_MemberFlags = "200"
Public Event DriveListDropdown()
Public Event DriveListCloseup()
Private Type DriveEntry
Name As String 'i.e. Local disk (C:)
Letter As String 'i.e. C
Path As String 'i.e. C:\
NameOld As String 'Name formatted like old drive control, i.e. c: [Local disk]
Type As DriveTypes
Removed As Boolean
nIcon As Long
Index As Long
End Type
Private mDrives() As DriveEntry
Private mDrivesPrv() As DriveEntry
Private mCt As Long, mCtPrv As Long
Private mWindows As String
Private mPrev As String
Private Sub UserControl_Initialize() 'Handles UserControl.Initialize
Dim hDC As LongPtr
hDC = GetDC(0&)
mDPI = GetDeviceCaps(hDC, LOGPIXELSY) / 96
ReleaseDC 0&, hDC
mWindows = String$(MAX_PATH, 0)
Dim lRet As Long
lRet = GetWindowsDirectoryW(StrPtr(mWindows), MAX_PATH) 'for picking default drive
If lRet > 3 Then
mWindows = Left$(mWindows, 3)
End If
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag) 'Handles UserControl.ReadProperties
mStd = PropBag.ReadProperty("ShowStandardDrives", mDefStd)
mOpt = PropBag.ReadProperty("ShowOpticalDrives", mDefOpt)
mNet = PropBag.ReadProperty("ShowNetworkDrives", mDefNet)
mUSB = PropBag.ReadProperty("ShowRemovableDrives", mDefUSB)
cxList = PropBag.ReadProperty("DropdownWidth", mDefCX)
cyList = PropBag.ReadProperty("DropdownHeight", mDefCY)
mStyle = PropBag.ReadProperty("ComboStyle", mDefStyle)
mHP = PropBag.ReadProperty("NoFixedUSB", mDefHP)
mBk = PropBag.ReadProperty("BackColor", mDefBk)
mNotify = PropBag.ReadProperty("MonitorChanges", mDefNotify)
mEnabled = PropBag.ReadProperty("Enabled", mDefEnabled)
mShowHidden = PropBag.ReadProperty("ShowHiddenDrives", mDefShowHidden)
InitControl
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag) 'Handles UserControl.WriteProperties
PropBag.WriteProperty "ShowStandardDrives", mStd, mDefStd
PropBag.WriteProperty "ShowOpticalDrives", mOpt, mDefOpt
PropBag.WriteProperty "ShowNetworkDrives", mNet, mDefNet
PropBag.WriteProperty "ShowRemovableDrives", mUSB, mDefUSB
PropBag.WriteProperty "DropdownWidth", cxList, mDefCX
PropBag.WriteProperty "DropdownHeight", cyList, mDefCY
PropBag.WriteProperty "ComboStyle", mStyle, mDefStyle
PropBag.WriteProperty "NoFixedUSB", mHP, mDefHP
PropBag.WriteProperty "BackColor", mBk, mDefBk
PropBag.WriteProperty "MonitorChanges", mNotify, mDefNotify
PropBag.WriteProperty "Enabled", mEnabled, mDefEnabled
PropBag.WriteProperty "ShowHiddenDrives", mShowHidden, mDefShowHidden
End Sub
Private Sub UserControl_InitProperties() 'Handles UserControl.InitProperties
mNet = mDefNet
mOpt = mDefOpt
mStd = mDefStd
mUSB = mDefUSB
cxList = mDefCX
cyList = mDefCY
mStyle = mDefStyle
mHP = mDefHP
mBk = mDefBk
mNotify = mDefNotify
mEnabled = mDefEnabled
mShowHidden = mDefShowHidden
End Sub
Private Sub UserControl_Resize() 'Handles UserControl.Resize
If hMain Then
Dim rc As RECT
Dim rcWnd As RECT
GetClientRect UserControl.hWnd, rc
SetWindowPos hMain, 0, 0, 0, rc.Right, cyList * mDPI, SWP_NOMOVE Or SWP_NOZORDER
With UserControl
MoveWindow hMain, 0, 0, .ScaleWidth, .ScaleHeight, 1
GetWindowRect hMain, rcWnd
If (rcWnd.Bottom - rcWnd.Top) <> .ScaleHeight Or (rcWnd.Right - rcWnd.Left) <> .ScaleWidth Then
.Extender.Height = .ScaleY((rcWnd.Bottom - rcWnd.Top), vbPixels, vbContainerSize)
End If
End With
End If
End Sub
Public Property Get BackColor() As OLE_COLOR: BackColor = mBk: End Property
Public Property Let BackColor(ByVal cr As OLE_COLOR)
mBk = cr
UserControl.BackColor = cr
End Property
Public Property Get ComboStyle() As UCDCType: ComboStyle = mStyle: End Property
Attribute ComboStyle.VB_Description = "Sets the type of combobox used. Cannnot be changed during runtime."
Public Property Let ComboStyle(ByVal Value As UCDCType): mStyle = Value: End Property
Public Property Get Enabled() As Boolean: Enabled = mEnabled: End Property
Attribute Enabled.VB_Description = "Sets whether the control is enabled."
Public Property Let Enabled(ByVal fEnable As Boolean)
If fEnable <> mEnabled Then
mEnabled = fEnable
If hMain Then
If mEnabled Then
EnableWindow hMain, CTRUE
Else
EnableWindow hMain, CFALSE
End If
End If
End If
End Property
#If TWINBASIC Then
Public Property Get DriveComboHwnd() As LongPtr: DriveComboHwnd = hMain: End Property
#Else
Public Property Get DriveComboHwnd() As Long: DriveComboHwnd = hMain: End Property
#End If
Public Property Get MonitorChanges() As Boolean: MonitorChanges = mStd: End Property
Attribute MonitorChanges.VB_Description = "Monitor for drives being added and removed and update list accordingly."
Public Property Let MonitorChanges(ByVal Value As Boolean)
If Value <> mNotify Then
mNotify = Value
If Ambient.UserMode Then
If mNotify Then
If hNotify = 0 Then
Dim tFilter As DEV_BROADCAST_DEVICEINTERFACE
tFilter.dbcc_size = LenB(tFilter)
tFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE
tFilter.dbcc_classguid = GUID_DEVINTERFACE_VOLUME
hNotify = RegisterDeviceNotification(hMain, tFilter, DEVICE_NOTIFY_WINDOW_HANDLE)
End If
Else
If hNotify Then
UnregisterDeviceNotification hNotify
hNotify = 0
End If
End If
End If
End If
End Property
Public Property Get ShowStandardDrives() As Boolean: ShowStandardDrives = mStd: End Property
Attribute ShowStandardDrives.VB_Description = "Include standard internal hard drives in the list."
Public Property Let ShowStandardDrives(ByVal Value As Boolean)
If Value <> mStd Then
mStd = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get ShowOpticalDrives() As Boolean: ShowOpticalDrives = mOpt: End Property
Attribute ShowOpticalDrives.VB_Description = "Include optical drives like DVD and BluRay drives in the list."
Public Property Let ShowOpticalDrives(ByVal Value As Boolean)
If Value <> mOpt Then
mOpt = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get ShowNetworkDrives() As Boolean: ShowNetworkDrives = mNet: End Property
Attribute ShowNetworkDrives.VB_Description = "Include mapped network drives in the list."
Public Property Let ShowNetworkDrives(ByVal Value As Boolean)
If Value <> mNet Then
mNet = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get ShowHiddenDrives() As Boolean: ShowHiddenDrives = mShowHidden: End Property
Attribute ShowHiddenDrives.VB_Description = "Show drives hidden from the user in Explorer."
Public Property Let ShowHiddenDrives(ByVal Value As Boolean)
If Value <> mShowHidden Then
mShowHidden = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get NoFixedUSB() As Boolean: NoFixedUSB = mHP: End Property
Attribute NoFixedUSB.VB_Description = "Never count USB mass storage as fixed (standard) drive."
Public Property Let NoFixedUSB(ByVal Value As Boolean)
If Value <> mHP Then
mHP = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get DropdownWidth() As Long: DropdownWidth = cxList: End Property
Attribute DropdownWidth.VB_Description = "Sets the width of the dropdown. Set to 0 to use default."
Public Property Let DropdownWidth(ByVal Value As Long)
If Value <> cxList Then
cxList = Value
If Ambient.UserMode Then
If cxList = 0 Then
Dim rc As RECT
GetClientRect hMain, rc
SendMessage hMain, CB_SETDROPPEDWIDTH, rc.Right, ByVal 0
Else
SendMessage hMain, CB_SETDROPPEDWIDTH, cxList * mDPI, ByVal 0
End If
End If
End If
End Property
Public Property Get DropdownHeight() As Long: DropdownHeight = cyList: End Property
Attribute DropdownHeight.VB_Description = "Sets the maximum height of the dropdown list of all drives."
Public Property Let DropdownHeight(ByVal Value As Long)
If Value <> cyList Then
cyList = Value
If Ambient.UserMode Then
UserControl_Resize
End If
End If
End Property
Public Property Get ShowRemovableDrives() As Boolean: ShowRemovableDrives = mNet: End Property
Attribute ShowRemovableDrives.VB_Description = "Include removable drives like USB flash drives in the list."
Public Property Let ShowRemovableDrives(ByVal Value As Boolean)
If Value <> mUSB Then
mUSB = Value
If Ambient.UserMode Then RefreshDriveList
End If
End Property
Public Property Get SelectedDriveLetter() As String
If Ambient.UserMode Then
Dim nIdx As Long
Dim nSel As Long
nSel = CLng(SendMessage(hMain, CB_GETCURSEL, 0, ByVal 0))
nIdx = -1
nIdx = CLng(GetCBXItemlParam(hMain, nSel))
SelectedDriveLetter = mDrives(nIdx).Letter
End If
End Property
Attribute SelectedDriveLetter.VB_MemberFlags = "400"
Public Property Let SelectedDriveLetter(ByVal sLetter As String)
If Ambient.UserMode Then
If mCt Then
Dim i As Long
For i = 0 To UBound(mDrives)
If LCase$(mDrives(i).Letter) = LCase$(sLetter) Then
SendMessage hMain, CB_SETCURSEL, mDrives(i).Index, ByVal 0
RaiseEvent SelectionChanged(mDrives(i).Path, mDrives(i).Letter, mDrives(i).Name, mDrives(i).Type)
End If
Next
End If
End If
End Property
Public Property Get SelectedDriveName() As String
If Ambient.UserMode Then
Dim nIdx As Long
Dim nSel As Long
nSel = CLng(SendMessage(hMain, CB_GETCURSEL, 0, ByVal 0))
nIdx = -1
nIdx = CLng(GetCBXItemlParam(hMain, nSel))
SelectedDriveName = mDrives(nIdx).Name
End If
End Property
Attribute SelectedDriveName.VB_MemberFlags = "400"
Public Property Let SelectedDriveName(ByVal sName As String)
If Ambient.UserMode Then
If mCt Then
Dim i As Long
For i = 0 To UBound(mDrives)
If LCase$(mDrives(i).Name) = LCase$(sName) Then
SendMessage hMain, CB_SETCURSEL, mDrives(i).Index, ByVal 0
RaiseEvent SelectionChanged(mDrives(i).Path, mDrives(i).Letter, mDrives(i).Name, mDrives(i).Type)
End If
Next
End If
End If
End Property
Public Property Get Drive() As String
If Ambient.UserMode Then
Dim nIdx As Long
Dim nSel As Long
nSel = CLng(SendMessage(hMain, CB_GETCURSEL, 0, ByVal 0))
nIdx = -1
nIdx = CLng(GetCBXItemlParam(hMain, nSel))
Drive = mDrives(nIdx).NameOld
End If
End Property
Attribute Drive.VB_MemberFlags = "400"
Public Property Let Drive(ByVal sName As String)
If Ambient.UserMode Then
If mCt Then
Dim i As Long
For i = 0 To UBound(mDrives)
If LCase$(mDrives(i).Letter) = LCase$(Left$(sName, 1)) Then
SendMessage hMain, CB_SETCURSEL, mDrives(i).Index, ByVal 0
RaiseEvent SelectionChanged(mDrives(i).Path, mDrives(i).Letter, mDrives(i).Name, mDrives(i).Type)
Exit Property
End If
Next
Err.Raise 68
End If
End If
End Property
Public Property Get SelectedDrivePath() As String
If Ambient.UserMode Then
Dim nIdx As Long
Dim nSel As Long
nSel = CLng(SendMessage(hMain, CB_GETCURSEL, 0, ByVal 0))
nIdx = -1
nIdx = CLng(GetCBXItemlParam(hMain, nSel))
SelectedDrivePath = mDrives(nIdx).Path
End If
End Property
Attribute SelectedDrivePath.VB_MemberFlags = "400"