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
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, StdCtrls, ShellApi;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure WMDropFiles(var msg : TWMDropFiles) ; message WM_DROPFILES;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(ListBox1.Handle, true);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DragAcceptFiles(ListBox1.Handle, false);
end;
procedure TForm1.WMDROPFILES(var Msg: TWMDropFiles);
const
MAXFILESIZE = 32767;
var
FileName: PChar;
I, NbFiles: integer;
begin
try
NbFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
for I := 0 to NbFiles - 1 do
begin
GetMem(FileName, MAXFILESIZE);
DragQueryFile(Msg.drop, I, FileName, MAXFILESIZE);
ListBox1.Items.Add(string(Filename)); // Filename contient aussi le path
FreeMem(FileName);
end;
finally
DragFinish(Msg.drop);
end;
Msg.Result:= 0;
end; |
Partager