Subversion Repositories delphiutils

Rev

Rev 5 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit DropFiles;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm2 = class(TForm)
  11.     Memo1: TMemo;
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     procedure HandleDroppedFile(acFileName: string);
  15.   public
  16.     procedure DropFiles( var msg : TMessage );
  17.       message WM_DROPFILES;
  18.     procedure SetMsg(s: string);
  19.     procedure SetCap(s: string);
  20.   end;
  21.  
  22. var
  23.   Form2: TForm2;
  24.  
  25. implementation
  26.  
  27. {$R *.dfm}
  28.  
  29. uses
  30.   ShellAPI;
  31.  
  32. procedure TForm2.HandleDroppedFile(acFileName: string);
  33. begin
  34.   // Showmessage(acFileName);
  35.   ShellExecute(Handle, 'open', PChar('"'+Application.ExeName+'"'), PChar('"'+acFileName+'"'), PChar('"'+ExtractFilePath(Application.ExeName)+'"'), SW_NORMAL);
  36.  
  37.   // Das ist Ansichtssache
  38.   // Close;
  39. end;
  40.  
  41. // Ref: http://www.chami.com/tips/delphi/111196D.html
  42.  
  43. (*
  44.  
  45.   public
  46.     procedure DropFiles( var msg : TMessage );
  47.       message WM_DROPFILES;
  48.  
  49. *)
  50.  
  51. procedure TForm2.DropFiles( var msg : TMessage );
  52. const
  53.   cnMaxFileNameLen = 255;
  54. var
  55.   i,
  56.   nCount     : integer;
  57.   acFileName : array [0..cnMaxFileNameLen] of char;
  58. begin
  59.   nCount := DragQueryFile( msg.WParam,
  60.                            $FFFFFFFF,
  61.                            acFileName,
  62.                            cnMaxFileNameLen );
  63.  
  64.   for i := 0 to nCount-1 do
  65.   begin
  66.     DragQueryFile( msg.WParam, i,
  67.                    acFileName, cnMaxFileNameLen );
  68.  
  69.     HandleDroppedFile(acFileName);
  70.   end;
  71.  
  72.   DragFinish( msg.WParam );
  73. end;
  74.  
  75. procedure TForm2.FormCreate(Sender: TObject);
  76. begin
  77.   DragAcceptFiles( Handle, True );
  78. end;
  79.  
  80. procedure TForm2.SetMsg(s: string);
  81. begin
  82.   Memo1.Text := s;
  83. end;
  84.  
  85. procedure TForm2.SetCap(s: string);
  86. begin
  87.   Caption := s + ' - ' + Caption;
  88. end;
  89.  
  90. end.
  91.