Aquí tienes el código del que te hablé antes.
Pon un TMemo llamado Memo1 alineado alTop y deja un espacio abajo para que aparezcan los dos paneles.
Código Delphi
[-]
unit UPruebaDragAndDrop;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, StdCtrls, ExtCtrls;
type
TPanelDragAndDrop = class(TCustomPanel)
private
FFiles : TStrings;
OriginalPanelWindowProc : TWndMethod;
FOnFileDrop : TNotifyEvent;
procedure PanelWindowProc (var Msg : TMessage);
procedure PanelFilesDrop (var Msg : TWMDROPFILES);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnFileDrop : TNotifyEvent read FOnFileDrop write FOnFileDrop;
property Files : TStrings read FFiles write FFiles;
end;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
procedure PanelFileDrop(Sender: TObject);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TPanelDragAndDrop.PanelWindowProc(var Msg: TMessage);
begin
if Msg.Msg = WM_DROPFILES then
PanelFilesDrop(TWMDROPFILES(Msg))
else
OriginalPanelWindowProc(Msg);
end;
procedure TPanelDragAndDrop.PanelFilesDrop(var Msg: TWMDROPFILES);
const
MAXFILENAME = 255;
var
cnt, FileCount : integer;
FileName : array [0..MAXFILENAME] of char;
begin
FileCount := DragQueryFile(msg.Drop, $FFFFFFFF, FileName, MAXFILENAME);
for cnt := 0 to -1 + FileCount do
begin
DragQueryFile(msg.Drop, cnt, FileName, MAXFILENAME);
FFiles.Add(FileName);
end;
DragFinish(msg.Drop);
if Assigned(OnFileDrop) then
OnFileDrop(Self);
end;
constructor TPanelDragAndDrop.Create(AOwner: TComponent);
begin
inherited;
FFiles := TStringList.Create;
Self.Parent := TWinControl(AOwner);
OriginalPanelWindowProc := WindowProc;
WindowProc := PanelWindowProc;
DragAcceptFiles(Handle, True);
end;
destructor TPanelDragAndDrop.Destroy;
begin
FFiles.Free;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
Panel : TPanelDragAndDrop;
begin
Panel := TPanelDragAndDrop.Create(Self);
Panel.Parent := Self;
Panel.Name := 'autoPanel1';
Panel.Align := alLeft;
Panel.Show;
Panel := TPanelDragAndDrop.Create(Self);
Panel.Parent := Self;
Panel.Name := 'autoPanel2';
Panel.Align := alRight;
Panel.Show;
for i := 0 to ComponentCount-1 do
begin
if (Components[i] is TPanelDragAndDrop) then
(Components[i] as TPanelDragAndDrop).OnFileDrop := PanelFileDrop;
end;
end;
procedure TForm1.PanelFileDrop(Sender: TObject);
var
i : integer;
begin
Memo1.Lines.Clear;
Memo1.Lines.Add(Format('Entraron %d archivos desde el panel %s', [TPanelDragAndDrop(Sender).Files.Count, TPanelDragAndDrop(Sender).Name]));
for i := 0 to TPanelDragAndDrop(Sender).Files.Count -1 do
begin
Memo1.Lines.Add(TPanelDragAndDrop(Sender).Files[i]);
end;
TPanelDragAndDrop(Sender).Files.Clear;
end;
end.