?
Solved

Windows Explorer to Virtual Treeview - Drag and Drop

Posted on 2005-05-08
6
Medium Priority
?
2,528 Views
Last Modified: 2013-11-18
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
Comment
Question by:devilduck
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13957767
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
 

Author Comment

by:devilduck
ID: 13980800
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
 

Author Comment

by:devilduck
ID: 14016260
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
 

Accepted Solution

by:
OzzMod earned 0 total points
ID: 14196710
Closed, 400 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0
 
LVL 1

Expert Comment

by:jplevene
ID: 29502669
For anybody looking for a solution, I found one at:

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

I used the TJamDropFiles.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question