AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Drag&Drop einer Datei in TreeView

Ein Thema von freak4fun · begonnen am 11. Mär 2009 · letzter Beitrag vom 27. Jan 2010
 
schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#9

Re: Drag&Drop einer Datei in TreeView

  Alt 25. Jan 2010, 16:09
Zitat von himitsu:
heißt doch wohl, daß die Drag&Drop-Nachrichten an die ListView gesendet werden sollen
und nicht an die Form, wo aktuell die Nachrichtenbehandlung implementiert wurde?

Oder man kann diese Art nicht verwenden und muß sich an anderer Stelle in die Message-Behandlung einschalten.
Bei ListBox1.Handle geht es das die Message Funktion in der MainForm die WM_DROPFILES Nachricht bekommt.
Bei TreeView1.Handle schaltet zwar der Cursor um jedoch kommt die Nachricht WM_DROPFILES nicht.

Aber es war der richtige Tipp!

So habe ich es nun hinbekommen:

Delphi-Quellcode:
type
  TMainForm= class(TForm)
    TreeView1 : TTreeView;
    .....

  private
    { Private-Deklarationen }
    OldLBWindowProc: TWndMethod;
  public
    { Public-Deklarationen }
    procedure WMDropFiles(var Msg: TMessage);
  end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  //save old windoproc:
  OldLBWindowProc := TreeView1.WindowProc;
  TreeView1.WindowProc := WMDropFiles;
  //enable drag and drop of treeview:
  DragAcceptFiles(TreeView1.Handle, True);

end;

procedure TMainForm.OnClose(Sender: TObject; var Action: TCloseAction);
begin
  //disable drag and drop of treeview:
  DragAcceptFiles(TreeView1.Handle, False);
end

//drag and drop:
procedure TMainForm.WMDropFiles(var Msg: TMessage);
var
  DropH: HDROP; // drop handle
  DroppedFileCount: Integer; // number of files dropped
  FileNameLength: Integer; // length of a dropped file name
  FileName: string; // a dropped file name
  I: Integer; // loops thru all dropped files
  DropPoint: TPoint; // point where files dropped
  AnItem : TTreeNode;
begin

  // Store drop handle from the message
  case Msg.Msg of

    WM_DROPFILES : begin
        DropH := Msg.WParam;
        try
          // Optional: Get point at which files were dropped
          DragQueryPoint(DropH, DropPoint);
          // ... do something with drop point here

          AnItem := TreeView1.GetNodeAt(DropPoint.X, DropPoint.Y) ;
          //only handle the drop if node was under drop mouse:
          if AnItem <> nil then
          begin
            // Get count of files dropped
            DroppedFileCount := DragQueryFile(DropH, $FFFFFFFF, nil, 0);
            // Get name of each file dropped and process it
            for I := 0 to Pred(DroppedFileCount) do
            begin
              // get length of file name
              FileNameLength := DragQueryFile(DropH, I, nil, 0);
              // create string large enough to store file
              // (Delphi allows for #0 terminating character automatically)
              SetLength(FileName, FileNameLength);
              // get the file name
              DragQueryFile(DropH, I, PWideChar(FileName), FileNameLength + 1);
              // process file name (application specific)
              // ... processing code here
            end;
          end;
        finally
          // Tidy up - release the drop handle
          // don't use DropH again after this
          DragFinish(DropH);
        end;
        // Note we handled message
        Msg.Result := 0;
    end; // WM_DROPFILES : begin
    //forward message to original WndProc:
    else OldLBWindowProc(Msg);
  end; //case Msg.Msg of
end;
Damit geht das Drag and Drop Event mit TreeView. Scheint zu gehen, bin mir aber nicht sicher ob es auch richtig "Save" ist.
Delphi 2010, Update 4 & 5
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:09 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz