AlanMar

UNIT_unMain

Mar 8th, 2011
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.12 KB | None | 0 0
  1. {********************************************************}
  2. {                                                        }
  3. {    Firesoft ShellNotify Demo - Form Main               }
  4. {                                                        }
  5. {    Copyright (c) Federico Firenze                      }
  6. {    Buenos Aires, Argentina                             }
  7. {                                                        }
  8. {********************************************************}
  9.  
  10. unit unMain;
  11.  
  12. {$IFNDEF VER110}
  13.   {$IFNDEF VER120}
  14.     {$IFNDEF VER130}
  15.       {$WARN UNIT_PLATFORM OFF}
  16.     {$ENDIF}
  17.   {$ENDIF}
  18. {$ENDIF}
  19.  
  20. interface
  21.  
  22. uses
  23.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  24.   ShellNotify, StdCtrls, FileCtrl;
  25.  
  26. type
  27.   TfrmMain = class(TForm)
  28.     bgNotifyPaths: TGroupBox;
  29.     lbPaths: TListBox;
  30.     btnAdd: TButton;
  31.     btnRemove: TButton;
  32.     btnClear: TButton;
  33.     GroupBox1: TGroupBox;
  34.     lbEvents: TListBox;
  35.     btnStart: TButton;
  36.     btnStop: TButton;
  37.     btnClearLog: TButton;
  38.     procedure btnStartClick(Sender: TObject);
  39.     procedure btnStopClick(Sender: TObject);
  40.     procedure btnRemoveClick(Sender: TObject);
  41.     procedure btnClearClick(Sender: TObject);
  42.     procedure btnAddClick(Sender: TObject);
  43.     procedure ShellNotifyNotify(Sender: TObject; Event: TShellNotifyEvent; Path1, Path2: AnsiString);
  44.     procedure btnClearLogClick(Sender: TObject);
  45.     procedure FormCreate(Sender: TObject);
  46.   private
  47.     ShellNotify: TShellNotify;
  48.     procedure CheckButtons;
  49.   end;
  50.  
  51. var
  52.   frmMain: TfrmMain;
  53.  
  54. implementation
  55.  
  56. {$R *.DFM}
  57.  
  58. procedure TfrmMain.btnStartClick(Sender: TObject);
  59. begin
  60.   ShellNotify.PathList.Assign(lbPaths.Items);
  61.   ShellNotify.Active := True;
  62.   CheckButtons;
  63. end;
  64.  
  65. procedure TfrmMain.btnStopClick(Sender: TObject);
  66. begin
  67.   ShellNotify.Active := False;
  68.   CheckButtons;
  69. end;
  70.  
  71. procedure TfrmMain.CheckButtons;
  72. var
  73.   AActive: Boolean;
  74. begin
  75.   AActive := ShellNotify.Active;
  76.   btnStart.Enabled := not AActive;
  77.   btnStop.Enabled := AActive;
  78. end;
  79.  
  80. procedure TfrmMain.btnRemoveClick(Sender: TObject);
  81. begin
  82.   if lbPaths.ItemIndex <> -1 then
  83.     lbPaths.Items.Delete(lbPaths.ItemIndex);
  84. end;
  85.  
  86. procedure TfrmMain.btnClearClick(Sender: TObject);
  87. begin
  88.   lbPaths.Items.Clear;
  89. end;
  90.  
  91. function GetTempDirectory: AnsiString;
  92. var
  93.   tempFolder: array[0..MAX_PATH] of AnsiChar;
  94. begin
  95.   Windows.GetTempPathA(MAX_PATH, @tempFolder);
  96.   Result := StrPas(tempFolder);
  97. end;
  98.  
  99. procedure TfrmMain.btnAddClick(Sender: TObject);
  100. var
  101.   TempDir: AnsiString;
  102. begin
  103.   TempDir := GetTempDirectory;
  104.   if not DirectoryExists(TempDir) then begin
  105.     ShowMessage('%TEMP% directory not found.');
  106.     Exit;
  107.   end;
  108.  
  109.   lbPaths.Items.Add(TempDir);  // 1
  110.   lbPaths.Items.Add(TempDir);  // 2
  111.   lbPaths.Items.Add(TempDir);  // 3
  112.   lbPaths.Items.Add(TempDir);  // 4
  113.   lbPaths.Items.Add(TempDir);  // 5
  114.   lbPaths.Items.Add(TempDir);  // 6
  115.   lbPaths.Items.Add(TempDir);  // 7
  116.   lbPaths.Items.Add(TempDir);  // 8
  117.   lbPaths.Items.Add(TempDir);  // 9
  118.   lbPaths.Items.Add(TempDir);  // 10
  119.   lbPaths.Items.Add(TempDir);  // 11
  120.   lbPaths.Items.Add(TempDir);  // 12
  121.   lbPaths.Items.Add(TempDir);  // 13
  122.   lbPaths.Items.Add(TempDir);  // 14
  123.   lbPaths.Items.Add(TempDir);  // 15
  124.   lbPaths.Items.Add(TempDir);  // 16
  125.   lbPaths.Items.Add(TempDir);  // 17
  126.   lbPaths.Items.Add(TempDir);  // 18
  127.   lbPaths.Items.Add(TempDir);  // 19
  128.   lbPaths.Items.Add(TempDir);  // 20
  129.   lbPaths.Items.Add(TempDir);  // 21
  130.   lbPaths.Items.Add(TempDir);  // 22
  131.   lbPaths.Items.Add(TempDir);  // 23
  132.   lbPaths.Items.Add(TempDir);  // 24
  133.   lbPaths.Items.Add(TempDir);  // 25
  134.   lbPaths.Items.Add(TempDir);  // 26
  135.   lbPaths.Items.Add(TempDir);  // 27
  136.   lbPaths.Items.Add(TempDir);  // 28
  137.   lbPaths.Items.Add(TempDir);  // 29
  138.   lbPaths.Items.Add(TempDir);  // 30
  139.   lbPaths.Items.Add(TempDir);  // 31
  140.   lbPaths.Items.Add(TempDir);  // 32
  141.   lbPaths.Items.Add(TempDir);  // 33
  142.   lbPaths.Items.Add(TempDir);  // 34
  143.   lbPaths.Items.Add(TempDir);  // 35
  144.   lbPaths.Items.Add(TempDir);  // 36
  145.   lbPaths.Items.Add(TempDir);  // 37
  146.   lbPaths.Items.Add(TempDir);  // 38
  147.   lbPaths.Items.Add(TempDir);  // 39
  148.   lbPaths.Items.Add(TempDir);  // 40
  149.   lbPaths.Items.Add(TempDir);  // 41
  150.   lbPaths.Items.Add(TempDir);  // 42
  151.   lbPaths.Items.Add(TempDir);  // 43
  152.   lbPaths.Items.Add(TempDir);  // 44
  153.   lbPaths.Items.Add(TempDir);  // 45
  154.   lbPaths.Items.Add(TempDir);  // 46
  155.   lbPaths.Items.Add(TempDir);  // 47 <--- OK up to here...
  156.   lbPaths.Items.Add(TempDir);  // 48 <--- causes EOSError
  157. end;
  158.  
  159.  
  160. procedure TfrmMain.ShellNotifyNotify(Sender: TObject; Event: TShellNotifyEvent; Path1, Path2: AnsiString);
  161. begin
  162.   // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shchangenotify.asp
  163.   case Event of
  164.     neAssocChanged:
  165.       lbEvents.Items.Add('A file type association has changed ' + Path1);
  166.     neAttributes:
  167.       lbEvents.Items.Add('The attributes of an item or folder have changed ' + Path1);
  168.     neCreate:
  169.       lbEvents.Items.Add('A nonfolder item has been created ' + Path1);
  170.     neDelete:
  171.       lbEvents.Items.Add('A nonfolder item has been deleted ' + Path1);
  172.     neDriveAdd:
  173.       lbEvents.Items.Add('A drive has been added ' + Path1);
  174.     neDriveAddGUI:
  175.       lbEvents.Items.Add('A drive has been added and the Shell should create a new window for the drive ' + Path1);
  176.     neDriveRemoved:
  177.       lbEvents.Items.Add('A drive has been removed ' + Path1);
  178.     neMediaInserted:
  179.       lbEvents.Items.Add('Storage media has been inserted into a drive ' + Path1);
  180.     neMediaRemoved:
  181.       lbEvents.Items.Add('Storage media has been removed from a drive ' + Path1);
  182.     neMkDir:
  183.       lbEvents.Items.Add('A folder has been created ' + Path1);
  184.     neNetShare:
  185.       lbEvents.Items.Add('A folder on the local computer is being shared via the network ' + Path1);
  186.     neNetUnshare:
  187.       lbEvents.Items.Add('A folder on the local computer is no longer being shared via the network ' + Path1);
  188.     neRenameFolder:
  189.       lbEvents.Items.Add('The name of a folder "' + Path1 + '" has changed to "' + Path2 + '"');
  190.     neRenameItem:
  191.       lbEvents.Items.Add('The name of a nonfolder item "' + Path1 + '" has changed to "' + Path2 + '"');
  192.     neRmDir:
  193.       lbEvents.Items.Add('A folder has been removed ' + Path1);
  194.     neServerDisconnect:
  195.       lbEvents.Items.Add('The computer has disconnected from a server ' + Path1);
  196.     neUpdateDir:
  197.       lbEvents.Items.Add('The contents of an existing folder have changed, but the folder still exists and has not been renamed ' + Path1);
  198.     neUpdateImage:
  199.       lbEvents.Items.Add('An image in the system image list has changed ' + Path1 + Path2);
  200.     neUpdateItem:
  201.       lbEvents.Items.Add('An existing nonfolder item has changed, but the item still exists and has not been renamed ' + Path1);
  202.     neOther:
  203.       lbEvents.Items.Add('Other "' + Path1 + '", "' + Path2 + '"');
  204.   end;
  205. end;
  206.  
  207. procedure TfrmMain.btnClearLogClick(Sender: TObject);
  208. begin
  209.   lbEvents.Items.Clear;
  210. end;
  211.  
  212. procedure TfrmMain.FormCreate(Sender: TObject);
  213. begin
  214.   ShellNotify := TShellNotify.Create(Self);
  215.   ShellNotify.OnNotify := ShellNotifyNotify;
  216. end;
  217.  
  218. end.
Advertisement
Add Comment
Please, Sign In to add comment