John Barrat wrote:

> I'm dragging and dropping files from Explorer to my Application using the
> ShellAPI unit.
> 
> On my form I have a listbox to which I want to drag files.
> 
> In form.create I add 
> 
> DragAcceptFiles(lstFiles.Handles, True);  //where lstFiles is my list box.
> 
> This appears to work - i.e. cursor changes to Accept drop but the
> WM_DROPFILES message is not received.
> 
> If I use the form's handle it works but of course the Accept Drop Cursor
> appears anywhere on the form.
> 
> The form is not the main form of the application and is brought up as a
> modal dialog.  I have the same code running successfully with a listbox
> control on the Main form in another application. Could this be the
> difference?
> 
> Also, how do I determine what files are attempting to be dropped?  Ideally I
> would like to test what was being dropped while it was being dragged and
> only show the Accept Drop mouse cursor when files of the correct type were
> being dropped.

I've appended a simple unit that shows how you can tweak TListBox 
to recognize Shell drag and drop.  This should get you started, 
but you're welcome to Email me if this gives you any trouble.

I've used what I call an "interposer" class to implement this 
quickly; but if you're going to be using this a lot, there may 
some percentage in wrapping this functionality into a new component.

Alternatively you might care to download the old TurboPower 
ShellShock library off SourceForge, it has a component to attach 
shell drag-drop functionality to any windowed control.

HTH

Stephen Posey
[EMAIL PROTECTED]

-------------------->8 cut here 8<--------------------
unit Unit1;

interface

uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, 
Controls, Forms,
   Dialogs, StdCtrls,

   ShellAPI;

type
   TListBox = class(StdCtrls.TListBox)
     procedure WMDropFiles(var Msg: TWMDropFiles);
       message WM_DROPFILES;
   end;

   TForm1 = class(TForm)
     ListBox1: TListBox;
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
   end;

var
   Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   DragAcceptFiles( ListBox1.Handle, True );
end;


{ TListBox }

procedure TListBox.WMDropFiles(var Msg: TWMDropFiles);
var
   Count: Integer;
   i: Integer;
   Buff: array [0..255] of Char;
   S: string;
begin
   // passing $FFFFFFFF for the second parameter
   // returns a count of dropped files
   Count := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
   ShowMessage(IntToStr(Count) + ' file(s) dropped.');
   for i := 0 to Count-1 do begin
     DragQueryFile(Msg.Drop, i, @Buff[0], SizeOf(Buff));
     S := Buff;
     Items.Add( S );
   end;
end;

end.
-------------------->8 cut here 8<--------------------

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://www.elists.org/mailman/listinfo/delphi

Reply via email to