File: AppletsAndWizards.pas

package info (click to toggle)
mysql-query-browser 1.1.6-1sarge0
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 36,320 kB
  • ctags: 24,680
  • sloc: pascal: 203,479; xml: 136,561; ansic: 47,502; cpp: 28,926; sh: 12,433; objc: 4,823; java: 1,849; php: 1,485; python: 1,225; sql: 1,128; makefile: 872
file content (855 lines) | stat: -rw-r--r-- 33,308 bytes parent folder | download
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
unit AppletsAndWizards;

// Version 1.2.0
//   The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.mozilla.org/MPL/
//
//   Software distributed under the License is distributed on an
// " AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or
// implied. See the License for the specific language governing rights
// and limitations under the License.
//
//
//   Alternatively, the contents of this file may be used under
// the terms of the GNU General Public License Version 2 or later
// (the "GPL"), in which case the provisions of the GPL are applicable
// instead of those above. If you wish to allow use of your version of
// this file only under the terms of the GPL and not to allow others to
// use your version of this file under the MPL, indicate your decision
// by deleting the provisions above and replace them with the notice and
// other provisions required by the GPL. If you do not delete the provisions
// above, a recipient may use your version of this file under either the
// MPL or the GPL.
//
// The initial developer of this code is Jim Kueneman <jimdk@mindspring.com>
//
//----------------------------------------------------------------------------

interface

{$include ..\Include\Compilers.inc}

//  Version 1.0.1
//
{ Jim Kueneman                                                          01.01.02 }
{ Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,     }
{ either express or implied.                                                     }
{ The initial developer of this code is Jim Kueneman <jimdk@mindspring.com>      }

{ Word of warning on the Return values of most of these functions.  They are    }
{ Boolean based on the result of WinExec.  The rundll32.exe will always run but }
{ the applet may not be present.  As such the result of the function is in NO   }
{ WAY representive of if the dialog actually popuped up.                        }
{                                                                               }
{ A future enhancement of this would be to incorporate a Execute And Wait       }
{ feature to the class.                                                         }
{                                                                               }
{ This unit encapsulates a number of shell dialogs and Windows property dialogs }
{ through the rundll32.exe applet/dll launch program and some undocumented SHxx }
{ functions.  Some applets allow the user to select a particular page in the    }
{ dialog.  Since the number of pages and layout of the dialogs changes with     }
{ each version of Windows the function allows a "Page" number to be passed.     }
{ These are "normal" pages for common dialogs, other will just have to be trial }
{ and error, most of this stuff is not documented so it can change, and does    }
{                                                                               }
{  Accessability Dialog                                                         }
{       Keyboard = 0                                                            }
{       Sound    = 1                                                            }
{       Display  = 2                                                            }
{       Mouse    = 3                                                            }
{       General  = 4                                                            }
{                                                                               }
{  Add/Remove Programs Dialog                                                   }
{       Install/Uninstall = 0                                                   }
{       Windows Setup     = 1                                                   }
{       Startup Disk      = 2                                                   }
{                                                                               }
{  Internet Settings Dialog                                                     }
{       General    = 0                                                          }
{       Security   = 1                                                          }
{       Content    = 2                                                          }
{       Connection = 3                                                          }
{       Programs   = 4                                                          }
{       Advanced   = 5                                                          }
{                                                                               }
{  Multimedia Settings Dialog                                                   }
{       Sound Settings   = 0                                                    }
{       Audio            = 1                                                    }
{       Video            = 2                                                    }
{       MIDI             = 3                                                    }
{       CDMUSIC          = 4                                                    }
{       Advanced Devices = 5                                                    }
{                                                                               }
{  Regional Settings Dialog                                                     }
{   NOTE: XP handles this differently thus these are of little use              }
{       Regional Settings = 0                                                   }
{       Number            = 1                                                   }
{       Currency          = 2                                                   }
{       Time              = 3                                                   }
{       Date              = 4                                                   }
{       Local Inputs      = 5                                                   }
{                                                                               }
{  Screen Settings Dialog                                                       }
{       Background   = 0                                                        }
{       Screen Saver = 1                                                        }
{       Appearance   = 2                                                        }
{       Settings     = 3                                                        }
{                                                                               }
{  System Settings Dialog                                                       }
{       This dialog is *highly* dependant on the operation system as to what    }
{       the title of the page may be.                                           }
{               This is Win2k sp 2                                              }
{               General      = 0                                                }
{               Network ID   = 1                                                }
{               Hardware     = 2                                                }
{               User Profile = 3                                                }
{               Advanced     = 4                                                }
{       WinXP has several more, WinNT4 different names etc.                     }
{                                                                               }
{  Time/Date Settings Dialog                                                    }
{       General   = 0                                                           }
{       Time Zone = 1                                                           }
{                                                                               }



uses
  Windows, Messages, SysUtils, Graphics, Controls, ShellAPI,
  ShlObj, Classes, Forms, VirtualShellUtilities, VirtualWideStrings;

resourcestring
  S_CONTROLPANEL = 'rundll32.exe shell32.dll,Control_RunDLL';

  { MultiPage Settings Dialogs }
  S_ACCESSABILITY = ' access.cpl'; // Add 1 - 5 to end of string to select initial page
  S_ADDREMOVEPROGRAM = ' appwiz.cpl'; // Add 0 - 2 to end of string to select initial page
  S_DISPLAYSETTINGS = ' desk.cpl'; // Add 0 - 3 to end of string to select initial page
  S_INTERNETCONNECTION = ' inetcpl.cpl'; // Add 0 - 5 to end of string to select initial page
  S_MULITMEDIA = ' mmsys.cpl'; // Add 0 - 4 to end of string to select initial page
  S_REGIONALSETTINGS = ' intl.cpl';  // Add 0 - 5 to end of string to select initial page
  S_SYSTEMSETTINGS = ' sysdm.cpl'; // Add 1 - 5 to end of string to select initial page
  S_TIMEDATE = ' timedate.cpl';
  { Modem Dialog }
  S_MODEM = ' modem.cpl';
  S_DIALINGPROPERTIES = ' telephon.cpl'; // WinNT only
  { Modem Dialog END}
  S_CONTROLPANELITEM = ' main.cpl @'; // Add 0 - 3 to end of string to select item
  S_FASTFIND = ' findfast.cpl';
  S_JOYSTICK = ' joy.cpl';
  S_SOUND = ' mmsys.cpl @1';
  S_EXCHANGEOUTLOOKPROPERTIES = ' mlcfg32.cpl';
  S_MAILPOSTOFFICE = ' wgpocpl.cpl';
  S_NETWORKCONFIG_NT = ' ncpa.cpl';
  S_NETWORKCONFIG_9X = ' netcpl.cpl';
  S_NETWORKSHARE = 'rundll32.exe ntlanui.dll,'; // Add ShareCreate or ShareManage  NT ONLY
  S_ODBCADMINISTRATOR = ' odbccp32.cpl';
  S_CHANGEPASSWORD = ' password.cpl'; // Win9x only
  S_COMPORTS = ' ports.cpl'; // WinNT only
  S_SERVERPROPERTIES = ' srvmgr.cpl'; // WinNT only
  S_ADDNEWHARDWARE = ' sysdm.cpl @1'; // Win9x only
  S_THEMEPROPERTIES = ' themes.cpl';
  S_UPS_POWEROPTIONS = ' ups.cpl'; // WinNT only
  S_TWEAKUI = ' tweakui.cpl';

  S_ADDNEWPRINTER = 'rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter'; // Win9x only
  S_DISPLAYINSTALLSCREENSAVER = 'rundll32.exe desk.cpl,InstallScreenSaver ';
  S_DIALUPWIZARD = 'rundll32.exe rnaui.dll,RnaWizard'; // Wi9x only
  S_OPENWITH = 'rundll32.exe shell32.dll,OpenAs_RunDLL d:\path\filename.ext';
  S_DISKCOPY = 'rundll32 diskcopy.dll,DiskCopyRunDll';
  S_VIEWFONTS = 'rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL FontsFolder';
  S_VIEWPRINTERS = 'rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder';
  S_CREATESHORTCUT = 'rundll32 AppWiz.Cpl,NewLinkHere ';

const
  { SHFormatDisk Constants }

  {$EXTERNALSYM SHFMT_NOFORMAT}
  SHFMT_NOFORMAT = $FFFFFFFD; // Drive is not formatable.
  {$EXTERNALSYM SHFMT_CANCEL}
  SHFMT_CANCEL = $FFFFFFFE;   // Last format was canceled.
  {$EXTERNALSYM SHFMT_ERROR}
  SHFMT_ERROR = $FFFFFFFF;   // Error, but drive may be formatable.

  { SHRunFileDlg Contants }

  {$EXTERNALSYM RFF_NOBROWSE}
  RFF_NOBROWSE      = $01;   // Removes the browse button.
  {$EXTERNALSYM RFF_NODEFAULT}
  RFF_NODEFAULT     = $02;   // No default item selected.
  {$EXTERNALSYM RFF_CALCDIRECTORY}
  RFF_CALCDIRECTORY = $04;   // Determines the work directory from the file name.
  {$EXTERNALSYM RFF_NOLABEL}
  RFF_NOLABEL       = $08;   // Removes the edit box label.
  {$EXTERNALSYM RFF_NOSEPARATEMEM}
  RFF_NOSEPARATEMEM = $20;   // Removes the Separate Memory check box (NT Only).

  {$EXTERNALSYM RFN_VALIDATE}
  RFN_VALIDATE      = -510;  // Notification code in WM_NOTIFY

  {$EXTERNALSYM RF_OK}
  RF_OK             = $00; // Allow the application to run.
  {$EXTERNALSYM RF_CANCEL}
  RF_CANCEL         = $01; // Cancel operation; close the dialog.
  {$EXTERNALSYM RF_RETRY}
  RF_RETRY          = $02; // Cancel operation; leave dialog open.

type
  PRunFileDlgA = ^TNM_RunFileDlgA;
  TNM_RunFileDlgA = packed record
    Hdr: TNMHdr;
    lpFile: PChar;
    lpDirectory: PChar;
    nShow: LongBool;
  end;

  PRunFileDlgW = ^TNM_RunFileDlgW;
  TNM_RunFileDlgW = packed record
    Hdr: TNMHdr;
    lpFile: PWideChar;
    lpDirectory: PWideChar;
    nShow: LongBool;
  end;

type
  TCmdShow = (
    swHide,              // Hides the window and activates another window.
    swMaximize,          // Maximizes the specified window.
    swMinimize,          // Minimizes the specified window and activates the next top-level window in the Z order.
    swRestore,           // Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    swShow,              // Activates the window and displays it in its current size and position.
    swShowDefault,       // Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
    swShowMinimized,     // Activates the window and displays it as a minimized window.
    swShowMinNoActive,   // Displays the window as a minimized window. The active window remains active.
    swShowNA,            // Displays the window in its current state. The active window remains active.
    swShowNoActive,      // Displays a window in its most recent size and position. The active window remains active.
    swShowNormal         // Activates and displays a window. If the window is minimized or maximized, Windows
  );

  TControlPanel = (
    ciControlPanel,
    ciMouse,
    ciKeyboard,
    ciJoyStick,
    ciFastFind,
    ciSound,
    ciNetworkConfig,
    ciODBCAdmin,
    ciChangePassword,           // Win9x Only
    ciComPorts,                 // NT Only
    ciServerProperties,         // NT Only
    ciAddNewHardware,           // Win9x Only
    ciAddNewPrinter,            // Win9x Only
    ciThemeProperties,
    ciUPS_PowerOptions,         // NT Only
    ciTweakUI                   // if installed
  );

  TShareWizard = (
    swCreate,
    swManage
  );

  TMicrosoftApp = (
    maOutlookExchangeProp,
    maMailPostOffice
  );

  TMiscApplets = (
    maOpenWith,
    maDiskCopy,
    msViewFonts,
    msViewPrinters,
    msDialupWizard              // Win9x Only
  );

  TModemSettings = (
    msModemOptions,
    msDialingProperties         // NT Only
  );

  TSystemDialogs = (
    sdFormatDrives
  );

  TSHFormatDriveCode = (
    fdNoError,
    fdNotFormatable,
    fdCancel,
    fdError
  );

  TVirtualRunFileDialogOption = (
    roNoBrowse,           // Removes Browse button
    roNoDefault,          // No default item selected.
    roCalDirectory,       // Determines the work directory from the file name.
    roNoLabel,            // Removes the edit box label.
    roNoSeparateMem       // Removes the Separate Memory check box (NT Only).
  );
  TVirtualRunFileDialogOptions = set of TVirtualRunFileDialogOption;

  TRunFileResult = (
    frOk,               // Allow the file to be run
    frCancel,           // Cancel the file about to be run
    frRetry             // Ask for another file
  );

type
  TAppletsAndWizards = class(TObject)
  private
    FCmdShow: TCmdShow;
    FShowErrorCodes: Boolean;
  protected
    function Launch(S: string): Boolean;
    function DecodeCmdShow(ACmdShow: TCmdShow): Longword;
    function EncodeCmdShow(SW_CODE: Longword): TCmdShow;
    function SelectPage(Command: string; Page: integer): Boolean;
  public
    constructor Create;
    function AccessabilityDialog(Page: integer): Boolean;
    function AddRemoveProgramsDialog(Page: integer): Boolean;
    function ControlPanel(Item: TControlPanel): Boolean;
    function CreateNewShortcut(Path: WideString): Boolean;
    function DisplayPropertiesDialog(Page: integer): Boolean;
    function SHFindComputer: Boolean;
    function SHFindFiles(Root, FilterSample: TNamespace): Boolean;
    function SHFormatDrive(DriveLetter: Char): TSHFormatDriveCode;
    function SHPickIconDialog(var FileName: WideString; var IconIndex: LongWord): Boolean;
    procedure SHRunFileDialog(Window: HWnd; Icon: HIcon; WorkingPath, Caption, Description: WideString; Options: TVirtualRunFileDialogOptions);
    function InstallScreenSaver(ScreenSaver: string): Boolean;
    function InternetSettingsDialog(Page: integer): Boolean;
    function MicrosoftApps(App: TMicrosoftApp): Boolean;
    function MiscApplets(Applet: TMiscApplets): Boolean;
    function ModemSettingsDialog(Page: TModemSettings): Boolean;
    function MultimediaSettingsDialog(Page: integer): Boolean;
    function NetworkShare(Wizard: TShareWizard): Boolean;
    function RegionalSettingsDialog(Page: integer): Boolean;
    function SystemSettingsDialog(Page: integer): Boolean;
    function TimeDateDialog(Page: integer): Boolean;

    property CmdShow: TCmdShow read FCmdShow write FCmdShow;
    property ShowErrorCodes: Boolean read FShowErrorCodes write FShowErrorCodes;
  end;


  TOnRunFile = procedure(RunFile, WorkingDirectory: string; var Result: TRunFileResult) of object;

  TVirtualRunFileDialog = class(TComponent)
  private
    FOptions: TVirtualRunFileDialogOptions;
    FDescription: string;
    FCaption: string;
    FWorkingPath: string;
    FIcon: TIcon;
    FFileToRun: string;
    FHiddenWnd: HWnd;
    FOnRunFile: TOnRunFile;
    FPosition: TPoint;
    procedure SetIcon(const Value: TIcon);
  protected
    procedure DoRunFile(RunFile, WorkingDirectory: string; var Result: TRunFileResult);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Run;
    procedure WindowProc(var Message: TMessage);

    property HiddenWnd: HWnd read FHiddenWnd write FHiddenWnd;
  published
    property Caption: string read FCaption write FCaption;
    property Description: string read FDescription write FDescription;
    property FileToRun: string read FFileToRun write FFileToRun;
    property Icon: TIcon read FIcon write SetIcon;
    property OnRunFile: TOnRunFile read FOnRunFile write FOnRunFile;
    property Options: TVirtualRunFileDialogOptions read FOptions write FOptions;
    property Position: TPoint read FPosition write FPosition;
    property WorkingPath: string read FWorkingPath write FWorkingPath;
  end;

var
   Applets: TAppletsAndWizards;


implementation

var
  FormatDrive: function(Owner: HWND; Drive: UINT; FormatID: UINT; OptionFlags: UINT): DWORD; stdcall;
  PickIconDlg: function(Owner: HWND; FileName: Pointer; MaxFileNameChars: DWORD; var IconIndex: DWORD): LongBool; stdcall;
  RunFileDlg: procedure (Owner: HWND; IconHandle: HICON; WorkPath: Pointer; Caption: Pointer; Description: Pointer; Flags: UINT); stdcall;
  FindFiles:  function(SearchRoot: PItemIDList; SavedSearchFile: PItemIDList): LongBool; stdcall;
  FindComputer: function(Reserved1: PItemIDList; Reserved2: PItemIDList): LongBool; stdcall;

  ShellDLL: HMODULE;

{ TAppletsAndWizards }

function TAppletsAndWizards.AccessabilityDialog(Page: integer): Boolean;
begin
  { This one is odd it is 1 indexed }
  Result := SelectPage(S_CONTROLPANEL + S_ACCESSABILITY, Page + 1);
end;

function TAppletsAndWizards.AddRemoveProgramsDialog(Page: integer): Boolean;
begin
  Result := SelectPage(S_CONTROLPANEL + S_ADDREMOVEPROGRAM, Page);
end;

function TAppletsAndWizards.ControlPanel(Item: TControlPanel): Boolean;
begin
  case Item of
    ciControlPanel:
        Result := Launch(S_CONTROLPANEL);
    ciMouse, ciKeyboard:
        Result := Launch(S_CONTROLPANEL + S_CONTROLPANELITEM + IntToStr(Ord(Item) - 1));
    ciJoyStick:
        Result := Launch(S_CONTROLPANEL + S_JOYSTICK);
    ciFastFind:
        Result := Launch(S_CONTROLPANEL + S_FASTFIND);
    ciSound:
        Result := Launch(S_CONTROLPANEL + S_SOUND);
    ciNetworkConfig:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
          Result := Launch(S_CONTROLPANEL + S_NETWORKCONFIG_NT)
        else
          Result := Launch(S_CONTROLPANEL + S_NETWORKCONFIG_9X);
    ciODBCAdmin:
        Result := Launch(S_CONTROLPANEL + S_ODBCADMINISTRATOR);
    ciChangePassword:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
           Result := False
         else
           Result := Launch(S_CONTROLPANEL + S_CHANGEPASSWORD);
    ciComPorts:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
           Result := Launch(S_CONTROLPANEL + S_COMPORTS)
         else
           Result := False;
    ciServerProperties:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
          Result := Launch(S_CONTROLPANEL + S_SERVERPROPERTIES)
         else
           Result := False;
    ciAddNewHardware:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
           Result := False
         else
           Result := Launch(S_CONTROLPANEL + S_ADDNEWHARDWARE);
    ciAddNewPrinter:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
           Result := False
         else
           Result := Launch(S_ADDNEWPRINTER);
    ciThemeProperties:
        Result := Launch(S_CONTROLPANEL + S_THEMEPROPERTIES);
    ciUPS_PowerOptions:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
          Result := Launch(S_CONTROLPANEL + S_UPS_POWEROPTIONS)
         else
           Result := False;
    ciTweakUI:
      Result := Launch(S_CONTROLPANEL + S_TWEAKUI)
  else
    Result := False;
  end;
end;

constructor TAppletsAndWizards.Create;
begin
  FCmdShow := swShowNormal;
  FShowErrorCodes := True;
end;

function TAppletsAndWizards.CreateNewShortcut(Path: WideString): Boolean;
begin
  Result := Launch(S_CREATESHORTCUT + Path);
end;

function TAppletsAndWizards.DecodeCmdShow(ACmdShow: TCmdShow): Longword;
begin
  case ACmdShow of
    swHide:             Result := SW_HIDE;
    swMaximize:         Result := SW_MAXIMIZE;
    swMinimize:         Result := SW_MINIMIZE;
    swRestore:          Result := SW_RESTORE;
    swShow:             Result := SW_SHOW;
    swShowDefault:      Result := SW_SHOWDEFAULT;
    swShowMinimized:    Result := SW_SHOWMINIMIZED;
    swShowMinNoActive:  Result := SW_SHOWMINNOACTIVE;
    swShowNA:           Result := SW_SHOWNA;
    swShowNoActive:     Result := SW_SHOWNOACTIVATE;
    swShowNormal:       Result := SW_SHOWNORMAL;
  else
    Result := SW_SHOWNORMAL
  end
end;

function TAppletsAndWizards.DisplayPropertiesDialog(Page: integer): Boolean;
begin
  Result := SelectPage(S_CONTROLPANEL + S_DISPLAYSETTINGS, Page);
end;

function TAppletsAndWizards.EncodeCmdShow(SW_CODE: Longword): TCmdShow;
begin
  case SW_CODE of
    SW_HIDE:            Result := swHide;
    SW_MAXIMIZE:        Result := swMaximize;
    SW_MINIMIZE:        Result := swMinimize;
    SW_RESTORE:         Result := swRestore;
    SW_SHOW:            Result := swShow;
    SW_SHOWDEFAULT:     Result := swShowDefault;
    SW_SHOWMINIMIZED:   Result := swShowMinimized;
    SW_SHOWMINNOACTIVE: Result := swShowMinNoActive;
    SW_SHOWNA :         Result := swShowNA;
    SW_SHOWNOACTIVATE : Result := swShowNoActive;
    SW_SHOWNORMAL:      Result := swShowNormal;
  else
    Result := swShowNormal
  end;
end;

function TAppletsAndWizards.InstallScreenSaver(ScreenSaver: string): Boolean;
begin
  Result := Launch(S_DISPLAYINSTALLSCREENSAVER + ScreenSaver);
end;

function TAppletsAndWizards.InternetSettingsDialog(Page: integer): Boolean;
begin
  Result := SelectPage(S_CONTROLPANEL + S_INTERNETCONNECTION, Page);
end;

function TAppletsAndWizards.Launch(S: string): Boolean;
begin
  Result := WinExec(PChar(S), DecodeCmdShow(CmdShow)) > 31;
  if not Result and ShowErrorCodes then
    {$ifdef COMPILER_6_UP}
    RaiseLastOSError;
    {$else}
    RaiseLastWin32Error;
   {$endif};
end;

function TAppletsAndWizards.MicrosoftApps(App: TMicrosoftApp): Boolean;
begin
  case App of
    maOutlookExchangeProp:
        Result := Launch(S_CONTROLPANEL + S_EXCHANGEOUTLOOKPROPERTIES);
    maMailPostOffice:
        Result := Launch(S_CONTROLPANEL + S_MAILPOSTOFFICE);
  else
    Result := False
  end
end;

function TAppletsAndWizards.MiscApplets(Applet: TMiscApplets): Boolean;
begin
  case Applet of
    maOpenWith: Result := Launch(S_OPENWITH);
    maDiskCopy: Result := Launch(S_DISKCOPY);
    msViewFonts: Result := Launch(S_VIEWFONTS);
    msViewPrinters: Result := Launch(S_VIEWPRINTERS);
    msDialUpWizard: Result := Launch(S_DIALUPWIZARD)
  else
    Result := False
  end
end;

function TAppletsAndWizards.ModemSettingsDialog(Page: TModemSettings): Boolean;
begin
  case Page of
    msModemOptions:
        Result := Launch(S_CONTROLPANEL + S_MODEM);

    msDialingProperties:
        if Win32Platform = VER_PLATFORM_WIN32_NT then
          Result := Launch(S_CONTROLPANEL + S_DIALINGPROPERTIES)
        else
          Result := Launch(S_CONTROLPANEL + S_MODEM)
  else
    Result := Launch(S_CONTROLPANEL + S_MODEM)
  end
end;

function TAppletsAndWizards.MultimediaSettingsDialog(Page: integer): Boolean;
begin
  { This seems to be off by 1. 0 is Sound and 1 is Audio in Win2k }
  Result := SelectPage(S_CONTROLPANEL + S_MULITMEDIA, Page);
end;

function TAppletsAndWizards.NetworkShare(Wizard: TShareWizard): Boolean;
begin
  Result := False;
  if Win32Platform = VER_PLATFORM_WIN32_NT then
    case Integer(Wizard) of
      0: Launch(S_NETWORKSHARE + 'ShareCreate');
      1: Launch(S_NETWORKSHARE + 'ShareManage');
    end
end;


function TAppletsAndWizards.RegionalSettingsDialog(Page: integer): Boolean;
begin
  Result := SelectPage(S_CONTROLPANEL + S_REGIONALSETTINGS, Page);
end;

function TAppletsAndWizards.SelectPage(Command: string; Page: integer): Boolean;
begin
  if Page > -1 then
    Result := Launch(Command + ',,' + IntToStr(Page))
  else
    Result := Launch(Command);
end;

function TAppletsAndWizards.SHFindComputer: Boolean;
begin
  { Parameters ignored }
  if Assigned(FindComputer) then
    Result := FindComputer(nil, nil)
  else
    Result := False;
end;

function TAppletsAndWizards.SHFindFiles(Root, FilterSample: TNamespace): Boolean;

{ To use the Filter an *EXISTING* file must be used, you can't use wildcards    }
{ To use a sample file do this to filter of *.txt files :                       }

//   NS := TNamespace.CreateFromFileName('C:\MyDir\SomeFile.txt');
//   Applets.SHFindFiles(DrivesFolder, NS);
//   NS.Free;

var
  PIDL1, PIDL2: PItemIDList;
begin
  if Assigned(FindFiles) then
  begin
    PIDL1 := nil;
    PIDL2 := nil;
    { Shell does not keep Root PIDL }
    if Assigned(Root) then
      PIDL1 := Root.AbsolutePIDL;
    { Per Holderness, Shell keeps second PIDL unless of an error }
    if Assigned(FilterSample) then
      PIDL2 := PIDLMgr.CopyPIDL(FilterSample.AbsolutePIDL);
    Result := FindFiles(PIDL1, PIDL2);
    { Per Holderness, if error we must free second PIDL }
    if not Result then
      PIDLMgr.FreePIDL(PIDL2);
  end else
    Result := False;
end;

function TAppletsAndWizards.SHFormatDrive(
  DriveLetter: Char): TSHFormatDriveCode;
{ There are ways to set up the dialog box checkboxes but they are either broken }
{ or backward in WinNT so lets not even try to support it.                      }
begin
  if Assigned(FormatDrive) then
  begin
    case FormatDrive(Application.Handle, Ord(UpCase(DriveLetter)) - $41, 0, 0) of
      SHFMT_NOFORMAT: Result := fdNotFormatable;
      SHFMT_CANCEL: Result := fdCancel;
      SHFMT_ERROR: Result := fdError;
    else
      Result := fdNoError
    end
  end else
    Result := fdError;
end;

function TAppletsAndWizards.SHPickIconDialog(var FileName: WideString;
  var IconIndex: LongWord): Boolean;
{ Returns False if User Canceled                                                }
{ The user may browse to a different file so check the filename on return       }
var
  s: string;
  OldLen: integer;
begin
  if Assigned(PickIconDlg) then
  begin
    IconIndex := 0;
    OldLen := Length(FileName);
    if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
    begin
      s := FileName;
      SetLength(s, MAX_PATH);
      s[OldLen + 1] := #0;
    end else
    begin
      SetLength(FileName, MAX_PATH);
      FileName[OldLen + 1] := #0;
    end;
    if Win32Platform = VER_PLATFORM_WIN32_NT then
    begin
      Result := PickIconDlg(Application.Handle, PWideChar(FileName), MAX_PATH, IconIndex);
      SetLength(FileName, lstrLenW(PWideChar(FileName)));
    end else
    begin
      Result := PickIconDlg(Application.Handle, PChar(s), MAX_PATH, IconIndex);
      SetLength(s, lstrLen(PChar(s)));
      FileName := s
    end
  end else
    Result := False;
end;

procedure TAppletsAndWizards.SHRunFileDialog(Window: HWnd; Icon: HIcon; WorkingPath, Caption,
  Description: WideString; Options: TVirtualRunFileDialogOptions);

{ To monitor what file is being run and to cancel or force a retry use the      }
{ TPickIconDlg component with the OnRunFile event.                              }
{ The component also gives more flexablilty in positioning of the dialog.       }

var
  DescriptionA, WorkingPathA, CaptionA: string;
  Flags: Longword;
begin
  if Assigned(PickIconDlg) then
  begin
    Flags := 0;
    if roNoBrowse in Options then       // Removes Browse button
      Flags := Flags or RFF_NOBROWSE;
    if roNoDefault in Options then      // No default item selected.
      Flags := Flags or RFF_NODEFAULT;
    if roCalDirectory in Options then   // Determines the work directory from the file name.
      Flags := Flags or RFF_CALCDIRECTORY;
    if roNoLabel in Options then        // Removes the edit box label.
      Flags := Flags or RFF_NOLABEL;
    if Win32Platform = VER_PLATFORM_WIN32_NT then
      if roNoSeparateMem in Options then  // Removes the Separate Memory check box (NT Only).
        Flags := Flags or RFF_NOSEPARATEMEM;

    if Window = 0 then
      Window := Application.Handle;
    if Win32Platform = VER_PLATFORM_WIN32_NT then
    begin
      RunFileDlg(Window, Icon, PWideChar(WorkingPath), PWideChar(Caption),
        PWideChar(Description), Flags);
    end else
    begin
      WorkingPathA := WorkingPath;
      CaptionA := Caption;
      DescriptionA := Description;
      RunFileDlg(Window, Icon, PChar(WorkingPathA), PChar(CaptionA),
        PChar(DescriptionA), Flags);
    end
  end
end;

function TAppletsAndWizards.SystemSettingsDialog(Page: integer): Boolean;
begin
  Result := SelectPage(S_CONTROLPANEL + S_SYSTEMSETTINGS, Page);
end;

function TAppletsAndWizards.TimeDateDialog(Page: integer): Boolean;
begin
  case Page of
    0: Result := Launch(S_CONTROLPANEL + S_TIMEDATE);
    1:   Result := Launch(S_CONTROLPANEL + S_TIMEDATE + ',,/f');
  else
    Result := False
  end
end;

{ TVirtualRunFileDialog }

constructor TVirtualRunFileDialog.Create(AOwner: TComponent);
begin
  inherited;
  FIcon := TIcon.Create;
end;

destructor TVirtualRunFileDialog.Destroy;
begin
  Icon.Free;
  inherited;
end;

procedure TVirtualRunFileDialog.DoRunFile(RunFile, WorkingDirectory: string;
  var Result: TRunFileResult);
begin
  if Assigned(OnRunFile) then
    OnRunFile(RunFile, WorkingDirectory, Result);
end;

procedure TVirtualRunFileDialog.Run;
const
  SizeFlag = SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE;
begin
  HiddenWnd := {$ifdef COMPILER_6_UP}Classes.{$endif}AllocateHWnd(WindowProc);
  SetWindowPos(HiddenWnd, 0, Position.x, Position.y, 0, 0, SizeFlag);
  Applets.SHRunFileDialog(HiddenWnd, Icon.Handle, WorkingPath, Caption, Description, Options);
  {$ifdef COMPILER_6_UP}Classes.{$endif}DeallocateHWnd(HiddenWnd);
end;

procedure TVirtualRunFileDialog.SetIcon(const Value: TIcon);
begin
  Icon.Assign(Value);
end;

procedure TVirtualRunFileDialog.WindowProc(var Message: TMessage);
var
  RunFileDlgA: PRunFileDlgA;
  RunFileDlgW: PRunFileDlgW;
  TempFilePathA, TempWorkingDirA: string;
  TempFilePathW, TempWorkingDirW: WideString;
  RunResult: TRunFileResult;   
begin
  case message.Msg of
    WM_NOTIFY:
       begin
         if Win32Platform = VER_PLATFORM_WIN32_NT then
         begin
           RunFileDlgW := PRunFileDlgW( TWMNotify( message).NMHdr);
           if RunFileDlgW.Hdr.code = RFN_VALIDATE then
           begin
             SetLength(TempFilePathW, lstrlenW(RunFileDlgW.lpFile));
             StrCopyW(PWideChar(TempFilePathW), PWideChar(RunFileDlgW.lpFile));
             SetLength(TempWorkingDirW, lstrlenW(RunFileDlgW.lpDirectory));
             StrCopyW(PWideChar(TempWorkingDirW), PWideChar(RunFileDlgW.lpDirectory));
             RunResult := frOk;
             DoRunFile(TempFilePathW, TempWorkingDirW, RunResult);
           end;
         end else
         begin
           RunFileDlgA := PRunFileDlgA( TWMNotify( message).NMHdr);
           if RunFileDlgA.Hdr.code = RFN_VALIDATE then
           begin
             SetLength(TempFilePathA, lstrlen(RunFileDlgA.lpFile));
             lstrcpy(PChar(TempFilePathA), RunFileDlgA.lpFile);
             SetLength(TempWorkingDirA, lstrlen(RunFileDlgA.lpDirectory));
             lstrcpy(PChar(TempWorkingDirA), RunFileDlgA.lpDirectory);
             RunResult := frOk;
             DoRunFile(TempFilePathA, TempWorkingDirA, RunResult);
           end;
         end;
         case RunResult of
           frOk:     message.Result := RF_OK;
           frCancel: message.Result := RF_CANCEL;
           frRetry:  message.Result := RF_RETRY;
         end;
       end;
  else
    message.Result := DefWindowProc(HiddenWnd, message.Msg, message.wParam, message.lParam);
  end;
end;

initialization
  ShellDLL := GetModuleHandle(PChar(Shell32));
 // ShellDLL := LoadLibrary(PChar(Shell32));
  if ShellDll <> 0 then
  begin
    FormatDrive := GetProcAddress(ShellDLL, 'SHFormatDrive');
    PickIconDlg := GetProcAddress(ShellDLL, PChar(62));
    RunFileDlg := GetProcAddress(ShellDLL, PChar(61));
    FindFiles := GetProcAddress(ShellDLL, PChar(90));
    FindComputer := GetProcAddress(ShellDLL, PChar(91));
  end;
  Applets := TAppletsAndWizards.Create;

finalization
  Applets.Free;

end.