Discussion:
drag drop files from explorer to control
(too old to reply)
Sanne
2003-11-27 12:07:29 UTC
Permalink
Does someone has an example how to drag files from explorer to a control,
like a listbox or a treeview? So not to the main app, but just the control.

Thanks
//sanne
Kurt Barthelmess (TeamB)
2003-11-27 17:47:18 UTC
Permalink
Post by Sanne
Does someone has an example how to drag files from explorer to a control,
like a listbox or a treeview? So not to the main app, but just the control.
It's pretty simple to register as a receiver. Just call
DragAcceptFiles. But then you need to "teach" the control what to do
when something is dropped on it by handling the WM_DROPFILES message.
Depending on what you expect the control to do, that can be easy or
complicated, but getting the files is simple:

procedure TSomething.WMDropFiles(var Msg: TWMDropFiles);
{ Notification that some files have been dropped on us }
var
BuffSize: Integer;
DropHandle: THandle;
FileCount: Integer;
FileName: string;
FileNo: Integer;
begin
{ Tell Windows we handled it }
with Msg do begin Result := 0; DropHandle := Drop; end;
{ Get the count of files }
FileCount := DragQueryFile(DropHandle, $FFFFFFFF, nil, 0);
{ For each file dropped onto us ... }
for FileNo := 0 to FileCount - 1 do
begin
{ Ask how big the name is }
BuffSize := DragQueryFile(DropHandle, FileNo, nil, 0) + 1;
{ Allocate space for it }
SetLength(FileName, BuffSize);
{ Get the name }
DragQueryFile(DropHandle, FileNo, @FileName[1], BuffSize);
{ Nuke the trailing NUL }
SetLength(FileName, Pos(#0, FileName) - 1);
{ Do "something" with FileName }
//
end;
{ Release the buffer }
DragFinish(DropHandle);
end;

Good luck.

Kurt
jason
2003-11-27 22:50:34 UTC
Permalink
Sanne,

You could try working with the MSHTML to get the details of the file when clicked on. Then OnDragDrop you could load those details into your listview, listbox, etc.

Info on TWebBrowser and DHTML/MSHTML can be found here:
http://groups.yahoo.com/group/delphi-webbrowser/

or if you're feeling brave, try MSDN:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp

Try playing around with the TWebBrowser's TWebBrowser.OleObject.Document object.

The answers are there so happy hunting.
Cheers,
Jason.
Sanne
2003-11-28 11:28:05 UTC
Permalink
subject only

Loading...