Ver Mensaje Individual
  #3  
Antiguo 24-10-2011
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.735
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
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
    { Private declarations }
    procedure PanelFileDrop(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

/// ********** ********** ********** ********** ********** **********
/// TPanelDragAndDrop
/// ********** ********** ********** ********** ********** **********
/// Descendiente de TCustomPanel
/// Acepta que le hechen archivos
/// Publica un evento OnFileDrop
/// Publica la lista de archivos que le cayeron
/// NO VACIA LA LISTA DE ARCHIVOS

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;

/// ********** ********** ********** ********** ********** **********
/// TForm1
/// ********** ********** ********** ********** ********** **********

procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
  Panel : TPanelDragAndDrop;
begin
  //Creo el panel1
  Panel := TPanelDragAndDrop.Create(Self);
  Panel.Parent := Self;
  Panel.Name := 'autoPanel1';
  Panel.Align := alLeft;
  Panel.Show;

  //Creo el panel2
  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.
Responder Con Cita