• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2580
  • Last Modified:

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(Sender: 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(DataObject, 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


0
devilduck
Asked:
devilduck
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hi
 
  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,Pchar(FileName),200);
  ListBox1.Items.Add(FileName)
end;

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

also look at this paq for more info
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21407519.html

If you still would like  VTV sample, I will give you later

Regards,
Mohammed
0
 
devilduckAuthor Commented:
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



0
 
devilduckAuthor Commented:
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
0
 
OzzModCommented:
Closed, 400 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0
 
jpleveneCommented:
For anybody looking for a solution, I found one at:

http://www.jam-software.com/shellbrowser_delphi/

I used the TJamDropFiles.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now