This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
EvilWorks.Vcl.BrowseDialog.pas
1387 lines (1238 loc) · 46.6 KB
/
EvilWorks.Vcl.BrowseDialog.pas
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
unit EvilWorks.VCL.BrowseDialog;
interface
uses
WinApi.Windows,
WinApi.Messages,
System.Classes,
WinApi.ShlObj,
Vcl.Dialogs,
Vcl.Graphics,
System.SysUtils,
WinApi.ActiveX,
Vcl.Controls,
Vcl.Forms,
Vcl.Consts;
const
{ Interfaces from ShObjIdl.h }
IID_IFolderFilterSite: TGUID = (D1: $C0A651F5; D2: $B48B; D3: $11D2; D4: ($B5, $ED, $00, $60, $97, $C6, $86, $F6));
SID_IFolderFilterSite = '{C0A651F5-B48B-11d2-B5ED-006097C686F6}';
type
IFolderFilterSite = interface(IUnknown)
[SID_IFolderFilterSite]
function SetFilter(punk: IUnknown): HResult; stdcall;
end;
const
IID_IFolderFilter: TGUID = (D1: $9CC22886; D2: $DC8E; D3: $11D2; D4: ($B1, $D0, $00, $C0, $4F, $8E, $EB, $3E));
SID_IFolderFilter = '{9CC22886-DC8E-11d2-B1D0-00C04F8EEB3E}';
type
IFolderFilter = interface(IUnknown)
[SID_IFolderFilter]
function ShouldShow(psf: IShellFolder; pidlFolder, pidlItem: PItemIDList): HResult; stdcall;
function GetEnumFlags(psf: IShellFolder; pidlFolder: PItemIDList; const phWnd: HWND; var pgrfFlags: DWORD): HResult; stdcall;
end;
type
TBrowsableObjectClass = (
ocFolders, // SHCONTF_FOLDERS,
ocNonFolders, // SHCONTF_NONFOLDERS,
ocIncludeHidden, // SHCONTF_INCLUDEHIDDEN,
ocInitOnFirstNext, // SHCONTF_INIT_ON_FIRST_NEXT,
ocNetPrinterSrch, // SHCONTF_NETPRINTERSRCH,
ocSharable, // SHCONTF_SHAREABLE,
ocStorage // SHCONTF_STORAGE
);
TBrowsableObjectClasses = set of TBrowsableObjectClass;
TBrowseAcceptChange = procedure(Sender: TObject; const NewFolder: string; var Accept: boolean) of object;
TShouldShowEvent = procedure(Sender: TObject; const Item: string; var DoShow: boolean) of object;
TGetEnumFlagsEvent = procedure(Sender: TObject; const AFolder: string; var Flags: TBrowsableObjectClasses) of object;
TDirChange = procedure(Sender: TObject; const Directory: string) of object;
TValidateFailedEvent = procedure(Sender: TObject; const AEditText: string; var CanCloseDialog: boolean) of object;
TFromDirectory = (
fdNoSpecialFolder, { 0 }
fdRootFolder, { 0 }
fdRecycleBin, { CSIDL_BITBUCKET }
fdControlPanel, { CSIDL_CONTROLS }
fdDesktop, { CSIDL_DESKTOP }
fdDesktopDirectory, { CSIDL_DESKTOPDIRECTORY }
fdMyComputer, { CSIDL_DRIVES }
fdFonts, { CSIDL_FONTS }
fdNetHood, { CSIDL_NETHOOD }
fdNetwork, { CSIDL_NETWORK }
fdPersonal, { CSIDL_PERSONAL }
fdPrinters, { CSIDL_PRINTERS }
fdPrograms, { CSIDL_PROGRAMS }
fdRecent, { CSIDL_RECENT }
fdSendTo, { CSIDL_SENDTO }
fdStartMenu, { CSIDL_STARTMENU }
fdStartup, { CSIDL_STARTUP }
fdTemplates, { CSIDL_TEMPLATES }
fdStartUpNonLocalized, { CSIDL_ALTSTARTUP }
fdCommonStartUpNonLocalized, { CSIDL_COMMON_ALTSTARTUP }
fdCommonDocuments, { CSIDL_COMMON_DOCUMENTS }
fdCommonFavorites, { CSIDL_COMMON_FAVORITES }
fdCommonPrograms, { CSIDL_COMMON_PROGRAMS }
fdCommonStartUp, { CSIDL_COMMON_STARTUP }
fdCommonTemplates, { CSIDL_COMMON_TEMPLATES }
fdCookies, { CSIDL_COOKIES }
fdFavorites, { CSIDL_FAVORITES }
fdHistory, { CSIDL_HISTORY }
fdInternet, { CSIDL_INTERNET }
fdMyMusic, { CSIDL_MYMUSIC }
fdPrinthood, { CSIDL_PRINTHOOD }
fdConnections, { CSIDL_CONNECTIONS }
{ Version 4.71 }
fdAppData, { CSIDL_APPDATA }
{ Version 4.72 }
fdInternetCache, { CSIDL_INTERNET_CACHE }
{ Version 5.00 }
fdAdminTools, { CSIDL_ADMINTOOLS }
fdCommonAdminTools, { CSIDL_COMMON_ADMINTOOLS }
fdCommonAppData, { CSIDL_COMMON_APPDATA }
fdLocalAppData, { CSIDL_LOCAL_APPDATA }
fdMyPictures, { CSIDL_MYPICTURES }
fdProfile, { CSIDL_PROFILE }
fdProgramFiles, { CSIDL_PROGRAM_FILES }
fdProgramFilesCommon, { CSIDL_PROGRAM_FILES_COMMON }
fdSystem, { CSIDL_SYSTEM }
fdWindows, { CSIDL_WINDOWS }
{ Version 6.00 }
fdCDBurnArea, { CSIDL_CDBURN_AREA }
fdCommonMusic, { CSIDL_COMMON_MUSIC }
fdCommonPictures, { CSIDL_COMMON_PICTURES }
fdCommonVideo, { CSIDL_COMMON_VIDEO }
fdMyDocuments, { CSIDL_MYDOCUMENTS }
fdMyVideo, { CSIDL_MYVIDEO }
fdProfiles, { CSIDL_PROFILES }
{ Unknown version }
fdResources, { CSIDL_RESOURCES }
fdResourcesLocalized,
fdCommonOEMLinks, { CSIDL_COMMON_OEM_LINKS }
fdComputersNearMe { CSIDL_COMPUTERSNEARME }
);
TFolderPos = (fpDefault, fpScreenCenter, fpFormCenter, fpTopLeft,
fpTopRight, fpBottomLeft, fpBottomRight);
TOptionsDirectory = (odBrowseForComputer, odOnlyDirectory, odOnlyPrinters,
odNoBelowDomain, odSystemAncestorsOnly, odFileSystemDirectoryOnly,
odStatusAvailable, odIncludeFiles, odIncludeUrls, odEditBox,
odNewDialogStyle, odShareable, odUsageHint, odNoNewButtonFolder, odValidate);
// (p3) shouldn't TOptionsDir be changed to T(Jv)OptionsDirectories?
TOptionsDir = set of TOptionsDirectory;
TBrowseDialog = class(TCommonDialog, IFolderFilter)
private
// (rom) changed names to Window and type to HWND
{ Handle to the owner form of the dialog, used if Position = fpFormCenter }
FOwnerWindow: HWND;
{ Handle to the MS "Browse for folder" dialog }
FDialogWindow : HWND;
FHelpContext : THelpContext;
FTitle : string;
FOptions : TOptionsDir;
FUsedOptions : TOptionsDir;
FDisplayName : string;
FRootDirectory : TFromDirectory;
FRootDirectoryPath: string;
FDirectory : string;
FPosition : TFolderPos;
FPidl : PItemIDList;
FStatusText : string;
FHelpButtonHandle : THandle;
FHelpButtonHeightDelta: integer;
FOnInit : TNotifyEvent;
FOnChange : TDirChange;
FOnAcceptChange : TBrowseAcceptChange;
FOnShouldShow : TShouldShowEvent;
FOnGetEnumFlags : TGetEnumFlagsEvent;
FOnValidateFailed: TValidateFailedEvent;
{ For hooking the control }
FDefWndProc : Pointer;
FObjectInstance: Pointer;
FPositionSet : boolean;
// (p3) updates the status text. NOTE: doesn't work if odNewDialogStyle is true (MS limitation)!!!
procedure UpdateStatusText(AText: string);
procedure WMShowWindow(var Msg: TMessage); message WM_SHOWWINDOW;
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
function GetRootDirectoryPath: string;
function IsRootDirectoryPathStored: boolean;
procedure SetRootDirectory(const Value: TFromDirectory);
procedure SetRootDirectoryPath(const Value: string);
procedure SetOptions(const Value: TOptionsDir);
protected
{ Messages from the browser }
procedure DoInitialized;
procedure DoIUnknown(const Unknown: IUnknown);
procedure DoSelChanged(IDList: PItemIDList);
function DoValidateFailed(AEditText: PChar): integer;
function DoValidateFailedW(AEditText: PChar): integer;
function DoShouldShow(const AItem: string): boolean;
function DoGetEnumFlags(const AFolder: string; var Flags: TBrowsableObjectClasses): boolean;
function GetOwnerWindow: HWND;
procedure MainWndProc(var Msg: TMessage);
procedure HookDialog;
{ IFolderFilter }
function ShouldShow(psf: IShellFolder; pidlFolder, pidlItem: PItemIDList): HResult; stdcall;
function GetEnumFlags(psf: IShellFolder; pidlFolder: PItemIDList; const phWnd: HWND; var pgrfFlags: DWORD): HResult; stdcall;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DefaultHandler(var Msg); override;
{ Messages to the browser }
procedure SetSelection(const APath: string); overload;
procedure SetSelection(IDList: PItemIDList); overload;
procedure SetStatusText(const AText: string);
procedure SetStatusTextW(const AText: string);
procedure SetOKEnabled(const Value: boolean);
procedure SetOKText(const AText: string);
procedure SetOKTextW(const AText: string);
procedure SetExpanded(const APath: string); overload;
procedure SetExpandedW(const APath: string);
procedure SetExpanded(IDList: PItemIDList); overload;
property Pidl: PItemIDList read FPidl;
property Handle: HWND read FDialogWindow;
function Execute: boolean; override;
published
property Directory : string read FDirectory write FDirectory;
property DisplayName : string read FDisplayName write FDisplayName stored False;
property HelpContext : THelpContext read FHelpContext write FHelpContext default 0;
property Options : TOptionsDir read FOptions write SetOptions default [odStatusAvailable, odNewDialogStyle];
property Position : TFolderPos read FPosition write FPosition default fpScreenCenter;
property RootDirectory : TFromDirectory read FRootDirectory write SetRootDirectory default fdNoSpecialFolder;
property RootDirectoryPath: string read GetRootDirectoryPath write SetRootDirectoryPath stored IsRootDirectoryPathStored;
property Title : string read FTitle write FTitle;
property StatusText : string read FStatusText write FStatusText;
property OnAcceptChange : TBrowseAcceptChange read FOnAcceptChange write FOnAcceptChange;
property OnChange : TDirChange read FOnChange write FOnChange;
property OnGetEnumFlags : TGetEnumFlagsEvent read FOnGetEnumFlags write FOnGetEnumFlags;
property OnInitialized : TNotifyEvent read FOnInit write FOnInit;
property OnShouldShow : TShouldShowEvent read FOnShouldShow write FOnShouldShow;
property OnValidateFailed : TValidateFailedEvent read FOnValidateFailed write FOnValidateFailed;
end;
function BrowseForFolder(const ATitle: string; AllowCreate: boolean; var ADirectory: string; AHelpContext: THelpContext = 0): boolean;
function BrowseForComputer(const ATitle: string; AllowCreate: boolean; var ADirectory: string; AHelpContext: THelpContext = 0): boolean;
// (p3) moved from JvFileUtil, deprecated removed
function BrowseDirectory(var AFolderName: string; const DlgText: string; AHelpContext: THelpContext): boolean;
// (p3) moved from JvFileUtil, deprecated removed
function BrowseComputer(var AComputerName: string; const DlgText: string; AHelpContext: THelpContext): boolean;
// Get version of Shell.dll
function GetShellVersion: cardinal;
{$EXTERNALSYM GetShellVersion}
function PidlFree(var IDList: PItemIDList): boolean;
function MinimizeFileName(const FileName: string; Canvas: TCanvas; MaxLen: integer): string;
implementation
type
TSHGetFolderPathProc = function(HWND: HWND; CSIDL: integer; hToken: THandle; dwFlags: DWORD; pszPath: PChar): HResult; stdcall;
var
SHGetFolderPathProc: TSHGetFolderPathProc = nil;
const
{ Taken from ShlObj.h & ShObjIdl.h }
BIF_RETURNFSANCESTORS = $0008;
BIF_EDITBOX = $0010; // Add an editbox to the dialog
BIF_VALIDATE = $0020; // insist on valid result (or CANCEL)
BIF_NEWDIALOGSTYLE = $0040; // Use the new dialog layout with the ability to resize
// Caller needs to call OleInitialize() before using this API
BIF_BROWSEINCLUDEURLS = $0080; // Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
BIF_UAHINT = $0100; // Add a UA hint to the dialog, in place of the edit box.
// May not be combined with BIF_EDITBOX
BIF_NONEWFOLDERBUTTON = $0200; // Do not add the "New Folder" button to the dialog.
// Only applicable with BIF_NEWDIALOGSTYLE.
BIF_BROWSEINCLUDEFILES = $4000; // Browsing for Everything
BIF_SHAREABLE = $8000; // sharable resources displayed (remote shares, requires BIF_USENEWUI)
SHCONTF_INIT_ON_FIRST_NEXT = $0100; // allow EnumObject() to return before validating enum
SHCONTF_NETPRINTERSRCH = $0200; // hint that client is looking for printers
SHCONTF_SHAREABLE = $0400; // hint that client is looking sharable resources (remote shares)
SHCONTF_STORAGE = $0800; // include all items with accessible storage and their ancestors
CSIDL_MYDOCUMENTS = $000C; // logical "My Documents" desktop icon
CSIDL_MYMUSIC = $000D; // "My Music" folder
CSIDL_MYVIDEO = $000E; // "My Videos" folder
CSIDL_LOCAL_APPDATA = $001C; // <user name>\Local Settings\Applicaiton Data (non roaming)
CSIDL_COMMON_APPDATA = $0023; // All Users\Application Data
CSIDL_WINDOWS = $0024; // GetWindowsDirectory()
CSIDL_SYSTEM = $0025; // GetSystemDirectory()
CSIDL_PROGRAM_FILES = $0026; // C:\Program Files
CSIDL_MYPICTURES = $0027; // C:\Program Files\My Pictures
CSIDL_PROFILE = $0028; // USERPROFILE
CSIDL_PROGRAM_FILES_COMMON = $002B; // C:\Program Files\Common
CSIDL_COMMON_TEMPLATES = $002D; // All Users\Templates
CSIDL_COMMON_DOCUMENTS = $002E; // All Users\Documents
CSIDL_COMMON_ADMINTOOLS = $002F; // All Users\Start Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = $0030; // <user name>\Start Menu\Programs\Administrative Tools
CSIDL_CONNECTIONS = $0031; // Network and Dial-up Connections
CSIDL_COMMON_MUSIC = $0035; // All Users\My Music
CSIDL_COMMON_PICTURES = $0036; // All Users\My Pictures
CSIDL_COMMON_VIDEO = $0037; // All Users\My Video
CSIDL_RESOURCES = $0038; // Resource Direcotry
CSIDL_RESOURCES_LOCALIZED = $0039; // Localized Resource Direcotry
CSIDL_COMMON_OEM_LINKS = $003A; // Links to All Users OEM specific apps
CSIDL_CDBURN_AREA = $003B; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
CSIDL_COMPUTERSNEARME = $003D; // Computers Near Me (computered from Workgroup membership)
CSIDL_PROFILES = $003E; // ??
BFFM_SETOKTEXT = WM_USER + 105; // Unicode only
BFFM_SETEXPANDED = WM_USER + 106; // Unicode only
BFFM_IUNKNOWN = 5; // provides IUnknown to client. lParam: IUnknown*
{ TOptionsDirectory = (odBrowseForComputer, odOnlyDirectory, odOnlyPrinters,
odNoBelowDomain, odSystemAncestorsOnly, odFileSystemDirectoryOnly,
odStatusAvailable, odIncludeFiles, odIncludeUrls, odEditBox,
odNewDialogStyle, odShareable, odUsageHint, odNoNewButtonFolder, odValidate);
}
{ (rb) No idea why odOnlyDirectory is used? }
COptionsDirectory: array [TOptionsDirectory] of cardinal = (
BIF_BROWSEFORCOMPUTER, 0, BIF_BROWSEFORPRINTER, BIF_DONTGOBELOWDOMAIN,
BIF_RETURNFSANCESTORS, BIF_RETURNONLYFSDIRS, BIF_STATUSTEXT,
BIF_BROWSEINCLUDEFILES, BIF_BROWSEINCLUDEURLS, BIF_EDITBOX,
BIF_NEWDIALOGSTYLE, BIF_SHAREABLE, BIF_UAHINT, BIF_NONEWFOLDERBUTTON,
BIF_VALIDATE);
{ TJvBrowseObjectClass = (ocFolders, ocNonFolders, ocIncludeHidden,
ocInitOnFirstNext, ocNetPrinterSrch, ocSharable, ocStorage)
}
CBrowseObjectClasses: array [TBrowsableObjectClass] of cardinal = (
SHCONTF_FOLDERS, SHCONTF_NONFOLDERS, SHCONTF_INCLUDEHIDDEN,
SHCONTF_INIT_ON_FIRST_NEXT, SHCONTF_NETPRINTERSRCH,
SHCONTF_SHAREABLE, SHCONTF_STORAGE);
function GetShellVersion: cardinal;
var
ShellVersion: cardinal;
begin
ShellVersion := GetFileVersion('shell32.dll');
Result := ShellVersion;
end;
function PidlFree(var IDList: PItemIDList): boolean;
var
Malloc: IMalloc;
begin
Result := False;
if IDList = nil then
Result := True
else
begin
if Succeeded(SHGetMalloc(Malloc)) and (Malloc.DidAlloc(IDList) > 0) then
begin
Malloc.Free(IDList);
IDList := nil;
Result := True;
end;
end;
end;
function MinimizeFileName(const FileName: string; Canvas: TCanvas; MaxLen: integer): string;
var
B: string;
R: TRect;
begin
B := FileName;
UniqueString(B);
R := Rect(0, 0, MaxLen, Canvas.TextHeight('Wq'));
if DrawText(Canvas.Handle, PChar(B), Length(B), R, DT_SINGLELINE or DT_MODIFYSTRING or DT_PATH_ELLIPSIS or DT_CALCRECT or DT_NOPREFIX) > 0 then
Result := string(PChar(B))
else
Result := FileName;
end;
function BrowseForFolder(const ATitle: string; AllowCreate: boolean; var ADirectory: string; AHelpContext: THelpContext): boolean;
begin
with TBrowseDialog.Create(nil) do
try
Position := fpScreenCenter;
Directory := ADirectory;
Title := ATitle;
HelpContext := AHelpContext;
if AllowCreate then
Options := Options + [odNewDialogStyle]
else
Options := Options - [odNewDialogStyle];
Result := Execute;
if Result then
ADirectory := Directory;
finally
Free;
end;
end;
function BrowseForComputer(const ATitle: string; AllowCreate: boolean; var ADirectory: string; AHelpContext: THelpContext): boolean;
begin
with TBrowseDialog.Create(nil) do
try
Position := fpScreenCenter;
Directory := ADirectory;
Title := ATitle;
HelpContext := AHelpContext;
if AllowCreate then
Options := Options + [odNewDialogStyle]
else
Options := Options - [odNewDialogStyle];
Options := Options + [odBrowseForComputer];
RootDirectory := fdNetwork;
Result := Execute;
if Result then
ADirectory := Directory;
finally
Free;
end;
end;
function BrowseDirectory(var AFolderName: string; const DlgText: string; AHelpContext: THelpContext): boolean;
begin
Result := BrowseForFolder(DlgText, True, AFolderName, AHelpContext);
end;
function BrowseComputer(var AComputerName: string; const DlgText: string; AHelpContext: THelpContext): boolean;
begin
Result := BrowseForComputer(DlgText, True, AComputerName, AHelpContext);
end;
{ From QDialogs.pas }
function StrRetToString(Pidl: PItemIDList; StrRet: TStrRet): string;
var
P: PChar;
begin
case StrRet.uType of
STRRET_CSTR:
SetString(Result, StrRet.cStr, Length(StrRet.cStr));
STRRET_OFFSET:
begin
P := @Pidl.mkid.abID[StrRet.uOffset - SizeOf(Pidl.mkid.cb)];
SetString(Result, P, Pidl.mkid.cb - StrRet.uOffset);
end;
STRRET_WSTR:
Result := StrRet.pOleStr;
end;
end;
type
TFromDirectoryData = record
CSIDL: cardinal;
MinVersion: cardinal;
OnlyNT: boolean;
CanSimulate: boolean;
Alternative: TFromDirectory;
end;
const
CSIDLLocations: array [TFromDirectory] of TFromDirectoryData = (
{ fdNoSpecialFolder }
(CSIDL: 0; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdRootFolder }
(CSIDL: 0; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdRecycleBin }
(CSIDL: CSIDL_BITBUCKET; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdControlPanel }
(CSIDL: CSIDL_CONTROLS; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdDesktop }
(CSIDL: CSIDL_DESKTOP; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdDesktopDirectory }
(CSIDL: CSIDL_DESKTOPDIRECTORY; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdMyComputer }
(CSIDL: CSIDL_DRIVES; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdFonts }
(CSIDL: CSIDL_FONTS; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdNetHood }
(CSIDL: CSIDL_NETHOOD; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdNetwork }
(CSIDL: CSIDL_NETWORK; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdPersonal }
(CSIDL: CSIDL_PERSONAL; MinVersion: 0; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdPrinters }
(CSIDL: CSIDL_PRINTERS; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdPrograms }
(CSIDL: CSIDL_PROGRAMS; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdRecent }
(CSIDL: CSIDL_RECENT; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdSendTo }
(CSIDL: CSIDL_SENDTO; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdStartMenu }
(CSIDL: CSIDL_STARTMENU; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdStartup }
(CSIDL: CSIDL_STARTUP; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdTemplates }
(CSIDL: CSIDL_TEMPLATES; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdStartUpNonLocalized }
(CSIDL: CSIDL_ALTSTARTUP; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonStartUpNonLocalized }
(CSIDL: CSIDL_COMMON_ALTSTARTUP; MinVersion: 0; OnlyNT: True;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonDocuments }
(CSIDL: CSIDL_COMMON_DOCUMENTS; MinVersion: 0; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdCommonFavorites }
(CSIDL: CSIDL_COMMON_FAVORITES; MinVersion: 0; OnlyNT: True;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonPrograms }
(CSIDL: CSIDL_COMMON_PROGRAMS; MinVersion: 0; OnlyNT: True;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonStartUp }
(CSIDL: CSIDL_COMMON_STARTUP; MinVersion: 0; OnlyNT: True;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonTemplates }
(CSIDL: CSIDL_COMMON_TEMPLATES; MinVersion: 0; OnlyNT: True;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCookies }
(CSIDL: CSIDL_COOKIES; MinVersion: 0; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdFavorites }
(CSIDL: CSIDL_FAVORITES; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdHistory }
(CSIDL: CSIDL_HISTORY; MinVersion: 0; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdInternet }
(CSIDL: CSIDL_INTERNET; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdMyMusic }
(CSIDL: CSIDL_MYMUSIC; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdPrinthood }
(CSIDL: CSIDL_PRINTHOOD; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdConnections }
(CSIDL: CSIDL_CONNECTIONS; MinVersion: 0; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdAppData }
(CSIDL: CSIDL_APPDATA; MinVersion: $00040071; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdInternetCache }
(CSIDL: CSIDL_INTERNET_CACHE; MinVersion: $00040072; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdAdminTools }
(CSIDL: CSIDL_ADMINTOOLS; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdCommonAdminTools }
(CSIDL: CSIDL_COMMON_ADMINTOOLS; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdCommonAppData }
(CSIDL: CSIDL_COMMON_APPDATA; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdLocalAppData }
(CSIDL: CSIDL_LOCAL_APPDATA; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdMyPictures }
(CSIDL: CSIDL_MYPICTURES; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdPersonal),
{ fdProfile }
(CSIDL: CSIDL_PROFILE; MinVersion: $00050000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdProgramFiles }
(CSIDL: CSIDL_PROGRAM_FILES; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdProgramFilesCommon }
(CSIDL: CSIDL_PROGRAM_FILES_COMMON; MinVersion: $00050000; OnlyNT: True;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdSystem }
(CSIDL: CSIDL_SYSTEM; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdWindows }
(CSIDL: CSIDL_WINDOWS; MinVersion: $00050000; OnlyNT: False;
CanSimulate: True; Alternative: fdNoSpecialFolder),
{ fdCDBurnArea }
(CSIDL: CSIDL_CDBURN_AREA; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonMusic }
(CSIDL: CSIDL_COMMON_MUSIC; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdCommonDocuments),
{ fdCommonPictures }
(CSIDL: CSIDL_COMMON_PICTURES; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdCommonDocuments),
{ fdCommonVideo }
(CSIDL: CSIDL_COMMON_VIDEO; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdCommonDocuments),
{ fdMyDocuments }
(CSIDL: CSIDL_MYDOCUMENTS; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdPersonal),
{ fdMyVideo }
(CSIDL: CSIDL_MYVIDEO; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdPersonal),
{ fdProfiles }
(CSIDL: CSIDL_PROFILES; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdResources }
(CSIDL: CSIDL_RESOURCES; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdResourcesLocalized }
(CSIDL: CSIDL_RESOURCES_LOCALIZED; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdCommonOEMLinks }
(CSIDL: CSIDL_COMMON_OEM_LINKS; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder),
{ fdComputersNearMe }
(CSIDL: CSIDL_COMPUTERSNEARME; MinVersion: $00060000; OnlyNT: False;
CanSimulate: False; Alternative: fdNoSpecialFolder)
);
procedure InitSHFolder;
const
SHFolderDll = 'SHFolder.dll';
var
SHFolderHandle: HMODULE;
begin
{ You never know, maybe someone does not have SHFolder.dll, thus load on request }
SHFolderHandle := GetModuleHandle(SHFolderDll);
if SHFolderHandle <> 0 then
@SHGetFolderPathProc := GetProcAddress(SHFolderHandle, 'SHGetFolderPathW');
end;
procedure GetCSIDLLocation(const ASpecialDirectory: TFromDirectory; var CSIDL: cardinal; var APath: string);
{ This function is a bit overkill }
var
LSpecialDirectory: TFromDirectory;
Buffer : PChar;
function IsOk: boolean;
begin
with CSIDLLocations[LSpecialDirectory] do
Result := (MinVersion <= GetShellVersion) and (not OnlyNT or (Win32Platform = VER_PLATFORM_WIN32_NT));
end;
begin
LSpecialDirectory := ASpecialDirectory;
while (LSpecialDirectory <> fdNoSpecialFolder) and not CSIDLLocations[LSpecialDirectory].CanSimulate do // and not IsOk do
LSpecialDirectory := CSIDLLocations[LSpecialDirectory].Alternative;
if (LSpecialDirectory = fdNoSpecialFolder) then // or IsOk then
begin
CSIDL := CSIDLLocations[LSpecialDirectory].CSIDL;
Exit;
end;
CSIDL := 0;
GetMem(Buffer, MAX_PATH);
try
if not Assigned(SHGetFolderPathProc) then
InitSHFolder;
if Assigned(SHGetFolderPathProc) and Succeeded(SHGetFolderPathProc(0, CSIDLLocations[LSpecialDirectory].CSIDL, 0, 0, Buffer)) then
APath := Buffer
else
APath := '';
finally
FreeMem(Buffer);
end;
end;
function CreateIDListFromPath(const APath: string): PItemIDList;
var
WS : string;
Eaten, Flags : longword;
IDesktopFolder: IShellFolder;
begin
{ Returned value must be freed }
Result := nil;
if APath = '' then
Exit;
WS := APath;
{ MSDN : Since Flags is an in/out parameter, it should always be initialized }
Flags := 0;
if Failed(SHGetDesktopFolder(IDesktopFolder)) or Failed(IDesktopFolder.ParseDisplayName(0, nil, pOleStr(WS), Eaten, Result, Flags)) then
Result := nil;
end;
function CreateIDListFromCSIDL(const ASpecialDirectory: TFromDirectory): PItemIDList;
var
CSIDL: cardinal;
Path : string;
begin
{ Returned value must be freed }
Result := nil;
if ASpecialDirectory = fdNoSpecialFolder then
Exit;
GetCSIDLLocation(ASpecialDirectory, CSIDL, Path);
if CSIDL <> 0 then
begin
{ MSDN: The calling application is responsible for freeing this pointer }
{ SHGetSpecialFolderLocation is shell v4.7 or later }
if Failed(SHGetSpecialFolderLocation(0, CSIDL, Result)) then
Result := nil;
end
else
Result := CreateIDListFromPath(Path);
end;
function IDListToPath(IDList: PItemIDList): string;
var
IDesktopFolder: IShellFolder;
StrRet : TStrRet;
begin
{ Similar to SHGetPathFromIDList }
if Succeeded(SHGetDesktopFolder(IDesktopFolder)) and Succeeded(IDesktopFolder.GetDisplayNameOf(IDList, SHGDN_NORMAL or SHGDN_FORPARSING, StrRet)) then
{ Result may be a GUID; Don't know whether these GUIDs are portable. Microsoft
does recommend to return strings 'that are as close to the display names
as possible'. But in this case display names aren't usable }
Result := StrRetToString(IDList, StrRet)
else
Result := '';
(* These GUID's seem pretty portable, you can enter them at RootDirectoryPath
or Directory, ie the "::{GUID}" part (only tested on Windows XP).
::{00020D75-0000-0000-C000-000000000046} - Inbox
::{20D04FE0-3AEA-1069-A2D8-08002B30309D} - CSIDL_DRIVES
::{208D2C60-3AEA-1069-A2D7-08002B30309D} - CSIDL_NETWORK, CSIDL_NETHOOD
::{21EC2020-3AEA-1069-A2DD-08002B30309D} - CSIDL_CONTROLS
::{2227A280-3AEA-1069-A2DE-08002B30309D} - CSIDL_PRINTERS, CSIDL_PRINTHOOD
::{450D8FBA-AD25-11D0-98A8-0800361B1103} - CSIDL_PERSONAL
::{645FF040-5081-101B-9F08-00AA002F954E} - CSIDL_BITBUCKET
::{7007ACC7-3202-11D1-AAD2-00805FC1270E} - CSIDL_CONNECTIONS
::{871C5380-42A0-1069-A2EA-08002B30309D} - CSIDL_INTERNET
::{D6277990-4C6A-11CF-8D87-00AA0060F5BF} - Scheduled Tasks
*)
end;
function CSIDLToPath(const ASpecialDirectory: TFromDirectory): string;
var
CSIDL : cardinal;
IDList : PItemIDList;
ShellMalloc: IMalloc;
begin
if ASpecialDirectory = fdNoSpecialFolder then
begin
Result := '';
Exit;
end;
GetCSIDLLocation(ASpecialDirectory, CSIDL, Result);
if CSIDL = 0 then
Exit;
{ SHGetSpecialFolderLocation is shell v4.7 or later }
if Succeeded(SHGetSpecialFolderLocation(0, CSIDL, IDList)) then
try
Result := IDListToPath(IDList);
finally
if Succeeded(SHGetMalloc(ShellMalloc)) then
ShellMalloc.Free(IDList);
end
else
Result := '';
end;
procedure SetDialogPos(AParentHandle, AWndHandle: THandle; Position: TFolderPos);
var
R, SR: TRect;
begin
if GetClientRect(AWndHandle, R) then
begin
// R.Right := R.Left + AWidth;
// R.Bottom := R.Top + AHeight;
SystemParametersInfo(SPI_GETWORKAREA, 0, @SR, 0);
case Position of
fpScreenCenter:
begin
R.Left := ((SR.Right - SR.Left - (R.Right - R.Left)) div 2);
R.Top := (SR.Bottom - SR.Top - (R.Bottom - R.Top)) div 2;
end;
fpFormCenter:
begin
GetWindowRect(AParentHandle, SR);
R.Left := SR.Left + ((SR.Right - SR.Left - (R.Right - R.Left)) div 2);
R.Top := SR.Top + (SR.Bottom - SR.Top - (R.Bottom - R.Top)) div 2;
end;
fpTopLeft:
begin
R.Left := SR.Left;
R.Top := SR.Top;
end;
fpTopRight:
begin
R.Top := SR.Top;
R.Left := SR.Right - (R.Right - R.Left) - GetSystemMetrics(SM_CXFIXEDFRAME);
end;
fpBottomLeft:
begin
R.Top := SR.Bottom - (R.Bottom - R.Top) - GetSystemMetrics(SM_CYCAPTION) - - GetSystemMetrics(SM_CYFIXEDFRAME);
R.Left := SR.Left;
end;
fpBottomRight:
begin
R.Top := SR.Bottom - (R.Bottom - R.Top) - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYFIXEDFRAME);
R.Left := SR.Right - (R.Right - R.Left) - GetSystemMetrics(SM_CXFIXEDFRAME);
end;
fpDefault:
Exit;
end;
SetWindowPos(AWndHandle, 0, R.Left, R.Top, 0, 0,
SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
end;
end;
// === { TBrowseForFolderDialog } ===========================================
function lpfnBrowseProc(Wnd: HWND; uMsg: UINT; lParam, lpData: lParam): integer; stdcall;
begin
Result := 0;
with TBrowseDialog(lpData) do
begin
FDialogWindow := Wnd;
case uMsg of
BFFM_INITIALIZED:
DoInitialized;
BFFM_SELCHANGED:
DoSelChanged(PItemIDList(lParam));
BFFM_IUNKNOWN:
DoIUnknown(IUnknown(lParam));
BFFM_VALIDATEFAILEDA:
Result := DoValidateFailed(PChar(lParam));
BFFM_VALIDATEFAILEDW:
Result := DoValidateFailedW(PChar(lParam));
end;
end;
end;
constructor TBrowseDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOptions := [odStatusAvailable, odNewDialogStyle];
FPosition := fpScreenCenter; // ahuser: changed from fpDefault - I think no one wants the dialog in the right bottom corner
FRootDirectory := fdNoSpecialFolder;
FObjectInstance := System.Classes.MakeObjectInstance(MainWndProc);
end;
destructor TBrowseDialog.Destroy;
begin
PidlFree(FPidl);
System.Classes.FreeObjectInstance(FObjectInstance);
inherited Destroy;
end;
procedure TBrowseDialog.DefaultHandler(var Msg);
begin
if FDialogWindow <> 0 then
with TMessage(Msg) do
Result := CallWindowProc(FDefWndProc, FDialogWindow, Msg, WParam, lParam)
else
inherited DefaultHandler(Msg);
end;
function TBrowseDialog.DoGetEnumFlags(const AFolder: string; var Flags: TBrowsableObjectClasses): boolean;
begin
{ (rb) Always return True? }
Result := True;
if Assigned(FOnGetEnumFlags) then
FOnGetEnumFlags(Self, AFolder, Flags);
end;
procedure TBrowseDialog.DoInitialized;
const
SBtn = 'BUTTON';
HelpButtonId = $FFFF;
var
BtnHandle, BtnFont : THandle;
BtnSize, WindowSize: TRect;
begin
{ We can now change the position of the dialog - if it's not NewDialogStyle.. }
FPositionSet := not (odNewDialogStyle in FUsedOptions);
if FPositionSet then
SetDialogPos(FOwnerWindow, FDialogWindow, Position);
{ ..Otherwise we have to delay the change until receive of WM_SHOWWINDOW,
thus we need to hook the dialog; we also need to hook the dialog if there
is a new help button on the dialog and the dialog is resizeable - ie
NewDialogStyle }
if not FPositionSet or ((FHelpContext <> 0) and (odNewDialogStyle in FUsedOptions)) then
HookDialog;
// [roko] Rx's code to insert Help button
if FHelpContext <> 0 then
begin
{ SomeBtnHandle is some button on the window; we need it to determine a
useable height & width for the new help button }
BtnHandle := FindWindowEx(FDialogWindow, 0, SBtn, nil);
if BtnHandle <> 0 then
begin
GetWindowRect(BtnHandle, BtnSize);
GetWindowRect(FDialogWindow, WindowSize);
ScreenToClient(FDialogWindow, BtnSize.TopLeft);
ScreenToClient(FDialogWindow, BtnSize.BottomRight);
BtnFont := SendMessage(FDialogWindow, WM_GETFONT, 0, 0);
{ Note: BtnSize.Top = "Window.Height" - FHelpButtonHeightDelta, used in
WM_SIZE }
FHelpButtonHeightDelta := WindowSize.Bottom - WindowSize.Top - BtnSize.Top;
{ Remember the new buttons handle, because we need it, when the dialog
is resized }
FHelpButtonHandle := CreateWindow(SBtn, PChar(SHelpButton), WS_CHILD or WS_CLIPSIBLINGS or WS_VISIBLE or BS_PUSHBUTTON or WS_TABSTOP, 12,
BtnSize.Top, BtnSize.Right - BtnSize.Left, BtnSize.Bottom - BtnSize.Top, FDialogWindow, HelpButtonId, HInstance, nil);
if BtnFont <> 0 then
SendMessage(FHelpButtonHandle, WM_SETFONT, BtnFont, MakeLParam(1, 0));
UpdateWindow(FDialogWindow);
end;
end;
{ Change directory (if possible) }
if FDirectory <> '' then
SetSelection(FDirectory);
UpdateStatusText(FDirectory);
if Assigned(FOnInit) then
FOnInit(Self);
end;
procedure TBrowseDialog.DoIUnknown(const Unknown: IUnknown);
var
FolderFilterSite: IFolderFilterSite;
begin
if (Assigned(FOnGetEnumFlags) or Assigned(FOnShouldShow)) and Supports(Unknown, IID_IFolderFilterSite, FolderFilterSite) then
begin
FolderFilterSite.SetFilter(Self);
FolderFilterSite := nil;
end;
end;
procedure TBrowseDialog.DoSelChanged(IDList: PItemIDList);
var
// (p3) use buff array instead of string as this works better
Buffer : array [0 .. MAX_PATH] of char;
Path : string;
Accept : boolean;
SavePidl: PItemIDList;
begin
{ Note :
* If the location specified by the pidl parameter is not part of the file
system, this function will fail.
* If the pidl parameter specifies a shortcut, the pszPath will contain the
path to the shortcut, not to the shortcut's target. (if not win XP )
Could also use IDListToPath
}
if SHGetPathFromIDList(IDList, Buffer) then
Path := Buffer
else
Path := '';
SavePidl := FPidl;
FPidl := IDList;
try
if Assigned(FOnAcceptChange) then
begin
Accept := True;
FOnAcceptChange(Self, Path, Accept);
SetOKEnabled(Accept);
end;
UpdateStatusText(Path);
if Assigned(FOnChange) then
FOnChange(Self, Path);
finally
FPidl := SavePidl;
end;
end;
function TBrowseDialog.DoShouldShow(const AItem: string): boolean;
begin
if Assigned(FOnShouldShow) then
FOnShouldShow(Self, AItem, Result)
else
Result := True;
end;
function TBrowseDialog.DoValidateFailed(AEditText: PChar): integer;
var
CanClose: boolean;
begin
{ Return zero to allow the dialog to be dismissed or nonzero to keep
the dialog displayed. }