Autor Beitrag
Handycommander
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: So 09.01.05 16:06 
Hallo,

ich möchte sowas wie der Windows-Explorer ist, in ein Form machen. Ich habe dazu 2 ShellTreeViews und 2 ShellListViews.

So nun zu meiner Frage:
Wie kann ich die Dateien, die ich markiere auf ShellListView1 zu ShellListView2 kopieren, sodass die Dateien auch dann, wenn ich mit dem Windows-Explorer in den Ordner gehe, wo ich die Dateien hinkopiert habe auch vorhanden sind.

Kann ich das mit CopyFile machen?
Könntet ihr mir da ein Beispiel geben? :roll:

MfG

Tobias
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 09.01.05 16:09 
Beispiel findest du zu hauf hier im Forum.
Wenn du mehrere Dateien mit einmal kopieren willst, gugg dir auch mal Suche in: Delphi-Forum, Delphi-Library SHFILEOPERATION an. Damit kannst du auch einfach die gewohnte Fortschritts-Animation anzeigen lassen.

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: So 09.01.05 16:31 
Hallo,

irgendwie blick ich da nicht ganz durch. Ich muss die Dateien und Ordner ja per Drag-And-Drop kopieren können. Also von einer ShellListView auf die andere ziehen, und dann sollte der das kopieren. Aber wie kann ich das machen?

Hat da jemand einen Vorschlag?

MfG

Tobias
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Fr 14.01.05 19:43 
Weiß denn keiner, wie ich die Datein per DragOver kopieren kann??
Bitte helft mir! :oops:

Dank

Tobias
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Fr 14.01.05 20:44 
ok, hatte übersehen, das dus mit Shelllistview machen willst. Mit den dingern habe ich noch nicht groß gearbeitet, gehen tuts aber trotzdem :)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
uses shellapi;

    procedure Kopieren(dir, dest: string);
    var sfos: TSHFileOpStruct;
      begin
        FillChar(sfos, SizeOf(sfos), 0);
        dir :=  dir +chr(0);
        dest := dest + chr(0);
        with sfos do
          begin
            wnd := form1.Handle;
            wfunc := FO_COPY;
            pFrom := PChar(dir);
            pTo := PChar(dest);
            fFlags := FOF_NOCONFIRMATION;
            fAnyOperationsAborted := false;
            hNameMappings := nil;
            lpszProgressTitle := nil;
          end;
        SHFileOperation(sfos);
      end;

procedure TForm1.ShellListView1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  accept := source is TShellListView;
end;

procedure TForm1.ShellListView1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var i:integer;
    s:string;
    src_slv:TShellListView;
begin
  if sender is TShellListView then
    begin
      src_slv:=source as TShellListView;
      s:='';
      for i := 0 to src_slv.Items.Count - 1 do
        if src_slv.Items[i].Selected then
          begin
            s:=s+src_slv.folders[i].PathName+#0; //für mehrere Dateine kopieren {http://www.delphi-forum.de/viewtopic.php?t=3772&highlight=mehrere+dateien+kopieren};
          end;
//      ShowMessage('von:'+s);//wird dir duch das #0 nicht viel anzeigen
//      ShowMessage('nach:'+(Sender as TShellListView).RootFolder.PathName);
      Kopieren(s,(Sender as TShellListView).RootFolder.PathName+'\');
    end;
end;

die drag*-ereignisse einmal erstellen und jeweils bei beiden shelllistviews zuweisen. duch das shfileoperation erhälst du auch gleich die fortschrittsanzeige mit.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 18:59 
Hallo,

danke für das Beispiel, leider klappt das bei mir nicht :cry:
Hab es genauso gemacht.
Ich kann keine Dateien per DragOver von ShellListView1 zu ShellListView2 ziehen.
Es bewegen sich nicht mal die Icons.
Außerdem will ich noch machen, dass da nicht der Kopieren-Dialog erscheint, sondern dass ich die Daten in eine ListView einfügen kann und somit sehe, wann was fertig ist.

Gibt es dazu auch noch ein Beispiel?

Danke und MfG

Tobias
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 19:16 
du mußt auch dragmode der beiden slv auf dmautomatic stellen

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 19:49 
Hallo,

ich kann die Daten nicht kopieren!!
Jetzt funktioniert es, dass ich die daten per DragOver rüberziehen kann, aber nicht kopieren.

MFG

Tobias
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:00 
Handycommander hat folgendes geschrieben:
Hallo,

ich kann die Daten nicht kopieren!!
Jetzt funktioniert es, dass ich die daten per DragOver rüberziehen kann, aber nicht kopieren.


hast dus mal im explorer probiert? dort sind die Daten schon kopiert. Ob dus gleich in deinen slv´s siehst, hängt wieder von deinen Einstellungen im OI ab. setzt autorefresh auf true, oder beim dragdrop ganz am ende:
ausblenden Delphi-Quelltext
1:
(Sender as TShellListView).Refresh;					

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:03 
Im Explorer is da nix
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:06 
also entweder stell ich mich hier zu blöd an, aber bei mir geht der code.
gibts irgendwelche fehlermeldungen, was sagen die 2 showmessages?

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:17 
Es gibt keine Fehlermeldungen
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:19 
und die showmessages?

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:21 
Da kommt gar nichts. Wenn ich die Datei von ShellListView1 zu ShellListView2 schiebe, dann kann ich die Datei rüberziehen, aber es passiert nichts.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:26 
dann sind die 2 ereignisse den beiden shelllistviews nicht richtig zugeordnet, prüf das bitte

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:30 
Habs aber genauso gemacht, wie du geschrieben hast
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:32 
Handycommander hat folgendes geschrieben:
Habs aber genauso gemacht, wie du geschrieben hast

dann zeig deinen code und das Formular (rechtsklick->ansicht als text und das posten)

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:40 
Hier ist der Code:


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ToolWin, ComCtrls, ShellCtrls, XPMan, Menus, StdCtrls, ShellApi;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Ansicht1: TMenuItem;
    Extras1: TMenuItem;
    Hilfe1: TMenuItem;
    XPManifest1: TXPManifest;
    StatusBar1: TStatusBar;
    ShellTreeView1: TShellTreeView;
    ShellTreeView2: TShellTreeView;
    ShellListView1: TShellListView;
    ShellListView2: TShellListView;
    ToolBar1: TToolBar;
    Button1: TButton;
    procedure ShellListView1DragDrop(Sender, Source: TObject; X,
      Y: Integer);
    procedure ShellListView2DragDrop(Sender, Source: TObject; X,
      Y: Integer);
    procedure ShellListView2DragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure ShellListView1DragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure Kopieren(dir, dest: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

    procedure TForm1.Kopieren(dir, dest: string);
    var sfos: TSHFileOpStruct;
      begin
        FillChar(sfos, SizeOf(sfos), 0);
        dir :=  dir +chr(0);
        dest := dest + chr(0);
        with sfos do
          begin
            wnd := form1.Handle;
            wfunc := FO_COPY;
            pFrom := PChar(dir);
            pTo := PChar(dest);
            fFlags := FOF_NOCONFIRMATION;
            fAnyOperationsAborted := false;
            hNameMappings := nil;
            lpszProgressTitle := nil;
          end;
        SHFileOperation(sfos);
      end;

procedure TForm1.ShellListView1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var i:integer;
    s:string;
    src_slv:TShellListView;
begin
  if sender is TShellListView then
    begin
      src_slv:=source as TShellListView;
      s:='';
      for i := 0 to src_slv.Items.Count - 1 do
        if src_slv.Items[i].Selected then
          begin
            s:=s+src_slv.folders[i].PathName+#0; //für mehrere Dateine kopieren {http://www.delphi-forum.de/viewtopic.php?t=3772&highlight=mehrere+dateien+kopieren};
          end;
//      ShowMessage('von:'+s);//wird dir duch das #0 nicht viel anzeigen
//      ShowMessage('nach:'+(Sender as TShellListView).RootFolder.PathName);
      Kopieren(s,(Sender as TShellListView).RootFolder.PathName+'\');
    end;
end;

procedure TForm1.ShellListView2DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var i:integer;
    s:string;
    src_slv:TShellListView;
begin
  if sender is TShellListView then
    begin
      src_slv:=source as TShellListView;
      s:='';
      for i := 0 to src_slv.Items.Count - 1 do
        if src_slv.Items[i].Selected then
          begin
            s:=s+src_slv.folders[i].PathName+#0; //für mehrere Dateine kopieren {http://www.delphi-forum.de/viewtopic.php?t=3772&highlight=mehrere+dateien+kopieren};
          end;
//      ShowMessage('von:'+s);//wird dir duch das #0 nicht viel anzeigen
//      ShowMessage('nach:'+(Sender as TShellListView).RootFolder.PathName);
      Kopieren(s,(Sender as TShellListView).RootFolder.PathName+'\');
    end;
end;

procedure TForm1.ShellListView2DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  accept := source is TShellListView;
end;

procedure TForm1.ShellListView1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  accept := source is TShellListView;
end;

end.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 15.01.05 20:49 
und das formular?
rechtklick ins formular, ansicht als text wählen und das posten

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Handycommander Threadstarter
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: Sa 15.01.05 20:50 
Da sind nur 2 ShellListViews und 2 ShellTreeViews.
Mehr nicht