devilduck
asked on
Windows Explorer to Virtual Treeview - Drag and Drop
Hello Experts!
I am using Mike Lischke's excellent Virtual Treeview (VTV) and need to implement drag and drop from Windows Explorer to the VTV.
The following code (from the VTV help file) implements D&D within the VTV, but I need help with the code to allow the VTV to accept the list of files that have been dropped on it from Windows Explorer.
procedure TMainForm.VTDragDrop(Sende r: TBaseVirtualTree; Source: TObject; DataObject: IDataObject;
const Formats: array of Word; Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
I: Integer;
AttachMode: TVTNodeAttachMode;
begin
if Length(Formats) > 0 then
begin
// OLE drag'n drop
// If the native tree format is listed then use this and accept the drop, otherwise recject (ignore) it.
// It is recommend by Microsoft to order available clipboard formats in decreasing detail richness so
// the first best format which we can accept is usually the best format we can get at all.
for I := 0 to High(Formats) do
if Formats[I] = CF_VIRTUALTREE then
begin
case Mode of
dmAbove:
AttachMode := amInsertBefore;
dmOnNode:
AttachMode := amAddChildLast;
dmBelow:
AttachMode := amInsertAfter;
else
if Assigned(Source) and (Source is TBaseVirtualTree) and (Sender <> Source) then
AttachMode := amInsertBefore
else
AttachMode := amNowhere;
end;
// in the case the drop target does an optimized move Effect is set to DROPEFFECT_NONE
// to indicate this also to the drag source (so the source doesn't need to take any further action)
Sender.ProcessDrop(DataObj ect, Sender.DropTargetNode, Effect, AttachMode);
Break;
end;
end
else
begin
// VCL drag'n drop, Effects contains by default both move and copy effect suggestion,
// as usual the application has to find out what operation is finally to do
Beep;
end;
end;
All I need is a StringList result of the top level folders and files that were dropped and I can dive into the folders to get the complete tree.
I will increase the points by 100 if the solution is well commented so I can more easily learn from your solution.
Thank you in advance for all of your help!
DD
I am using Mike Lischke's excellent Virtual Treeview (VTV) and need to implement drag and drop from Windows Explorer to the VTV.
The following code (from the VTV help file) implements D&D within the VTV, but I need help with the code to allow the VTV to accept the list of files that have been dropped on it from Windows Explorer.
procedure TMainForm.VTDragDrop(Sende
const Formats: array of Word; Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
I: Integer;
AttachMode: TVTNodeAttachMode;
begin
if Length(Formats) > 0 then
begin
// OLE drag'n drop
// If the native tree format is listed then use this and accept the drop, otherwise recject (ignore) it.
// It is recommend by Microsoft to order available clipboard formats in decreasing detail richness so
// the first best format which we can accept is usually the best format we can get at all.
for I := 0 to High(Formats) do
if Formats[I] = CF_VIRTUALTREE then
begin
case Mode of
dmAbove:
AttachMode := amInsertBefore;
dmOnNode:
AttachMode := amAddChildLast;
dmBelow:
AttachMode := amInsertAfter;
else
if Assigned(Source) and (Source is TBaseVirtualTree) and (Sender <> Source) then
AttachMode := amInsertBefore
else
AttachMode := amNowhere;
end;
// in the case the drop target does an optimized move Effect is set to DROPEFFECT_NONE
// to indicate this also to the drag source (so the source doesn't need to take any further action)
Sender.ProcessDrop(DataObj
Break;
end;
end
else
begin
// VCL drag'n drop, Effects contains by default both move and copy effect suggestion,
// as usual the application has to find out what operation is finally to do
Beep;
end;
end;
All I need is a StringList result of the top level folders and files that were dropped and I can dive into the folders to get the complete tree.
I will increase the points by 100 if the solution is well commented so I can more easily learn from your solution.
Thank you in advance for all of your help!
DD
ASKER
Hi Mohammed,
Thank you for your reply.
This solution doesn't appear to work with the virtual treeview. It works with other controls with no problem, but the virtual treeview has internal drag and drop handling that I want to utilize.
The help file example allows nodes to be easily dragged within the treeview, which is working very well.
From the help file:
The native format is registered as CF_VIRTUALTREE while other typical formats include CF_TEXT or CF_HDROP. Note that, because Virtual Treeview is already OLE drag'n drop aware, you do not need to register its window for accepting file drops. If the user drops files onto a Virtual Treeview window you will get the CF_HDROP format in the format list passed to OnDragDrop.
Basically, if I am passed an IDataObject as format CF_HDROP I need to be able to extract the filenames that the user dropped from it.
At least, that is how I think it works.
Thank you,
DD
Thank you for your reply.
This solution doesn't appear to work with the virtual treeview. It works with other controls with no problem, but the virtual treeview has internal drag and drop handling that I want to utilize.
The help file example allows nodes to be easily dragged within the treeview, which is working very well.
From the help file:
The native format is registered as CF_VIRTUALTREE while other typical formats include CF_TEXT or CF_HDROP. Note that, because Virtual Treeview is already OLE drag'n drop aware, you do not need to register its window for accepting file drops. If the user drops files onto a Virtual Treeview window you will get the CF_HDROP format in the format list passed to OnDragDrop.
Basically, if I am passed an IDataObject as format CF_HDROP I need to be able to extract the filenames that the user dropped from it.
At least, that is how I think it works.
Thank you,
DD
ASKER
I figured out what I needed to do.
Virtual Shell Tools (http://www.mustangpeak.net/) has an object (THDrop) that allows you to read an IDataObject that is format CF_DROP.
Using the object allows Virtual Treeview to use its own internal drag/drop handling and handle OLE drag/drop.
Thank you,
DD
Virtual Shell Tools (http://www.mustangpeak.net/) has an object (THDrop) that allows you to read an IDataObject that is format CF_DROP.
Using the object allows Virtual Treeview to use its own internal drag/drop handling and handle OLE drag/drop.
Thank you,
DD
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For anybody looking for a solution, I found one at:
http://www.jam-software.com/shellbrowser_delphi/
I used the TJamDropFiles.
http://www.jam-software.com/shellbrowser_delphi/
I used the TJamDropFiles.
This is a sample I made for another question, but it based on ListBox not VTV, but the idea still the same
Drop a ListBox on your form, then handle wm_DropFiles message, and it will accept the files, try this sample
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm4 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DropFiles (var Msg: TWmDropFiles); message wm_DropFiles;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
uses
ShellAPI;
procedure TForm4.DropFiles(var Msg: TWmDropFiles);
var
FileName: string;
begin
SetLength(FileName,200);
DragQueryFile(Msg.Drop,0,P
ListBox1.Items.Add(FileNam
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;
also look at this paq for more info
https://www.experts-exchange.com/questions/21407519/Accept-dragged-item-from-the-desktop.html
If you still would like VTV sample, I will give you later
Regards,
Mohammed