一个文件拖放Panel

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

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