unit FileDropPan;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls;<br><br>type<br> TDragFileEvent = procedure (Sender: TComponent; FileList: TStrings) of object;<br><br> TAIFileDropPan = class(TPanel)<br> private<br> { Private declarations }<br> FDragFileEvent: TDragFileEvent;<br> FAcceptFile: boolean;<br> procedure SetAcceptFile(const Value: boolean);<br> protected<br> { Protected declarations }<br> FileList: TStringList;<br> public<br> { Public declarations }<br> procedure WithDropFIles(var Msg: TMessage); message WM_DROPFILES;<br> constructor Create(AOwner: TComponent); override;<br> destructor Destroy; override;<br> published<br> { Published declarations }<br> property OnDragFile :TDragFileEvent read FDragFileEvent write FDragFileEvent;<br> property AcceptFile: boolean read FAcceptFile write SetAcceptFile;<br> end;<br><br>procedure Register;<br><br>implementation<br>Uses ShellAPI;<br><br>procedure Register;<br>begin<br> RegisterComponents('Voice', [TAIFileDropPan]);<br>end;<br><br>constructor TAIFileDropPan.Create(AOwner: TComponent);<br>begin<br> Inherited Create(AOwner);<br> parent := AOwner As TWinControl;<br> AcceptFile := true;<br> FileList := TStringList.Create;<br>end;<br><br>destructor TAIFileDropPan.Destroy;<br>begin<br> if parent <> nil then<br> if AcceptFile then AcceptFile := false;<br><br> FileList.Free;<br> inherited;<br>end;<br><br>procedure TAIFileDropPan.SetAcceptFile(const Value: boolean);<br>begin<br> FAcceptFile := Value;<br> DragAcceptFiles(Handle, FAcceptFile);<br>end;<br><br>procedure TAIFileDropPan.WithDropFIles(var Msg: TMessage);<br>Var<br> Buffer: Array[0..255] of Char;<br> count: Integer;<br> intX: Integer;<br>begin<br> count := DragQueryFile( Msg.WParam, $FFFFFFFF, Buffer, 255);<br> FileList.Clear;<br> for intX := 0 to count-1 do<br> begin<br> DragQueryFile( Msg.WParam, intX, Buffer, 255);<br> FileList.Add( Buffer);<br> end;<br> DragFinish( Msg.WParam);<br> if Assigned(FDragFileEvent) then<br> FDragFileEvent(Self, FileList);<br>end;<br><br>end.<br>我写的控件,从Panel继承过来的。能够接收拖放的文件,上面放置的其他控件也能接收文件。