参考了一下以前别人写的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls ;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
protected
{ Private declarations }
public
{ Public declarations }
procedure wmdropfiles(var msg: Tmessage); message WM_DROPFILES;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
dragacceptfiles(handle,true);
end;
procedure TForm1.wmdropfiles(var msg: Tmessage);
var a:Thandle;
b:array[0..255] of char;
k,
j:integer;
strs:TstringList;//ÕâÀï·ÅµÄÊÇÎļþÃûÁбí.ÓÐÁËÕâ¸öÁбí,ÄãÏë¸ÉÂð¾Í¸ÉÂð.
begin
strs:=TstringList.create;
a:=thandle(msg.wparam);
k:=dragqueryfile(a,$FFFFFFFF,b,100);
for j:=0 to k-1 do
begin
dragqueryfile(a,j,b,100);
strs.add(strpas(b));
end;
DragFinish(msg.Wparam);
for K := 0 to strs.Count - 1 do
ListBox1.Items.Add(strs[K]);
strs.Free;
end;
end.