unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TListBox =
class(StdCtrls.TListBox)
private
procedure WMDROPFILES(
var Msg: TMessage);
Message WM_DROPFILES;
end;
type
TForm1 =
class(TForm)
ListBox1: TListBox;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ShellAPI;
procedure TListBox.WMDROPFILES(
var Msg: TMessage);
var
i, Counts, Size: Integer;
PCharFileName: PChar;
begin
inherited;
PCharFileName :=
nil;
Counts := DragQueryFile(Msg.WParam, $FFFFFFFF, PCharFileName, 255);
for i := 0
to Counts - 1
do
begin
Size := DragQueryFile(Msg.WParam, i,
nil, 0) + 1;
PCharFileName := StrAlloc(Size);
DragQueryFile(Msg.WParam, i, PCharFileName, Size);
Items.Add(
String(PCharFileName));
StrDispose(PCharFileName);
end;
DragFinish(Msg.WParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(ListBox1.Handle, True);
end;
end.