Re:Drag&Drop From Non-Delphi Apps?
Quote
j...@armory.com (Jon Shemitz) wrote:
>I've used Drag And Drop to move things around within a Delphi app, and they've
>sure made it nice and easy. But now I want to do something really, really
>simple - accept a filename from filemanager &c - and I can't seem to do it.
>OnDragOver doesn't get called when I drag a filename from File Manager over
>the component. A cursory glimpse at the VCL source makes it look like there
>*isn't* anything to cast 'alien' draggees to a TObject - is this *really* so?
>Do I have to do drag 'n drop from out of my app at the API level?
Yes. Look at "Drag-Drop functions (3.1)" in Deplhi's Winapi help file for the
details, here is some code (make a form with a list box ListBox1):
{---------------------}
uses ShellApi;
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;
procedure TForm1.FileDropHandler(var Msg: TWMDropFiles);
const
qfFileCount = word(-1); {Pass to DragQueryFile to get # of files in operation}
var
i, c: integer;
s: array[0..127] of char;
begin
c := DragQueryFile(Msg.Drop, qfFileCount, nil, 0);
for i := 0 to c - 1 do
begin
DragQueryFile(Msg.Drop, i, @s, 128);
ListBox1.Items.Add(StrPas(@s));
end;
DragFinish(Msg.Drop);
end;
{---------------------}
For the last procedure, add this declaration to the TForm1 object:
procedure FileDropHandler(var Msg: TWMDropFiles); message WM_DROPFILES;
I have no idea if this even works in Win95 with the Explorer. Not that it
matters to me.
-Tony Lownds (lown0...@maroon.tc.umn.edu)