Discussion:
Drag-and-drop from Windows Explorer?
(too old to reply)
k***@gmail.com
2005-10-31 15:48:27 UTC
Permalink
I've recently used programs which accept files or folders dragged from
another window and dropped onto the application (e.g. this is one way
of adding files to Nero Burning ROM). However, Delphi (6, PE) only
seems to support dropping objects dragged from elsewhere in the same
application.

I've searched the help files (the new, improved ones I downloaded last
year) and they don't seem to contain any useful advice.

Any pointers? (If that was a pun it wasn't intended...)
Maarten Wiltink
2005-10-31 16:18:01 UTC
Permalink
Post by k***@gmail.com
I've recently used programs which accept files or folders dragged from
another window and dropped onto the application (e.g. this is one way
of adding files to Nero Burning ROM). However, Delphi (6, PE) only
seems to support dropping objects dragged from elsewhere in the same
application.
I've searched the help files (the new, improved ones I downloaded last
year) and they don't seem to contain any useful advice.
Any pointers? (If that was a pun it wasn't intended...)
The VirtualTreeview has two drag&drop modes: Delphi-compatible and
Windows/Explorer-compatible. The documentation was somewhat scathing
about this IIRC. I imagine there is some explanation there.

Groetjes,
Maarten Wiltink
Mike Shkolnik
2005-10-31 21:06:57 UTC
Permalink
See the sample code:
*************************************************
Delphi tip#58: to accept the dropped files
http://www.scalabium.com/faq/dct0058.htm
*************************************************

--
With best regards, Mike Shkolnik
E-mail: ***@scalabium.com
WEB: http://www.scalabium.com
Post by k***@gmail.com
I've recently used programs which accept files or folders dragged from
another window and dropped onto the application (e.g. this is one way
of adding files to Nero Burning ROM). However, Delphi (6, PE) only
seems to support dropping objects dragged from elsewhere in the same
application.
I've searched the help files (the new, improved ones I downloaded last
year) and they don't seem to contain any useful advice.
Any pointers? (If that was a pun it wasn't intended...)
Jamie
2005-11-02 02:56:14 UTC
Permalink
Post by k***@gmail.com
I've recently used programs which accept files or folders dragged from
another window and dropped onto the application (e.g. this is one way
of adding files to Nero Burning ROM). However, Delphi (6, PE) only
seems to support dropping objects dragged from elsewhere in the same
application.
I've searched the help files (the new, improved ones I downloaded last
year) and they don't seem to contain any useful advice.
Any pointers? (If that was a pun it wasn't intended...)
that is not a function of delphi but of the win32 api.
you can capture and register a window to except a
dropped string message.
since Delphi does work with the API it makes it very
easy to do.
first you use the "DragAcceptFiles(Form1.handle, True)
to register the form as a window that will accept the
WM_DROPFILES message.
you handle this message when it comes in.
the hDrop Handle is an unlocked memory chuck handle
that needs to be used in the "DragQueryFile" api., then
the "DragFinish" API needs to to be called in order to
free the memory via the handle that was given you.
normally this handle is an global unlock handle to a
chuck of memory that some other app created and so it
must be created using an API to call and not your local
memory functions. if the drop lands on a window that is
not registered or the message you handle does not return
return 0 indicating that you didn't want to process it
for what ever reason? windows then frees it other wise
the receiving window must free it.
--
Real Programmers Do things like this.
http://webpages.charter.net/jamie_5
Ryan Styles
2005-11-02 00:59:30 UTC
Permalink
On Tue, 01 Nov 2005 18:56:14 -0800, Jamie
Post by Jamie
that is not a function of delphi but of the win32 api.
you can capture and register a window to except a
dropped string message.
since Delphi does work with the API it makes it very
easy to do.
first you use the "DragAcceptFiles(Form1.handle, True)
to register the form as a window that will accept the
WM_DROPFILES message.
you handle this message when it comes in.
the hDrop Handle is an unlocked memory chuck handle
that needs to be used in the "DragQueryFile" api., then
the "DragFinish" API needs to to be called in order to
free the memory via the handle that was given you.
normally this handle is an global unlock handle to a
chuck of memory that some other app created and so it
must be created using an API to call and not your local
memory functions. if the drop lands on a window that is
not registered or the message you handle does not return
return 0 indicating that you didn't want to process it
for what ever reason? windows then frees it other wise
the receiving window must free it.
Thought I would toss this example out there for you that someone was
kind enough to share with me once:

uses
ShellApi;

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

procedure TForm1.WMDROPFILES(var Msg: TWMDropFiles);
var
i, amount: Integer;
FileName: array[0..MAX_PATH] of Char;
begin
inherited;
try
Amount := DragQueryFile(Msg.Drop, $FFFFFFFF, FileName, MAX_PATH);

for i := 0 to (Amount - 1) do
begin
DragQueryFile(Msg.Drop, i, FileName, MAX_PATH);
RichEdit1.Lines.LoadFromFile(FileName);
end;
finally
DragFinish(Msg.Drop);
end;
end;

-------

As you can see, this is to load the contents of a file into a
TRichEdit on my form. I am sure you can adapt this to whatever your
needs may be, korax.

Good luck with it!

-- Ryan

Loading...