怎样实现把在一个ShellListview中选中的多个文件或文件夹拖放到另一个ShellListview中(既copy过来)?

Allblus 2006-04-21 01:40:24
如题。

希望高手指点。
...全文
282 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Allblus 2006-04-22
  • 打赏
  • 举报
回复
谢谢你的帮忙,这个问题解决了,可还有其他问题,我都不要意思问了:)

现在写代码完全是ctrl+c,ctrll+v

唉!
老之 2006-04-21
  • 打赏
  • 举报
回复
修改了一下:
ShellListView1.MultiSelect:=True;

procedure TForm1.ShellListView2DragDrop(Sender, Source: TObject; X,
Y: Integer);
var SourceName,DestName:string;
i:integer;
SL:TStringList;
begin
SL:=TStringList.Create;
for i:=0 to ShellListView1.Items.Count-1 do
if ShellListView1.Items.Item[i].Selected then
SL.Add(ShellListView1.Folders[i].PathName);
for i:=0 to SL.Count-1 do
begin
SourceName:=SL.Strings[i];
DestName:=ShellListView2.RootFolder.PathName+'\'+ExtractFileName(SourceName);
Copy(SourceName,DestName);
end;
FreeAndNil(SL);
end;
Allblus 2006-04-21
  • 打赏
  • 举报
回复
上面的不可以选中多个,我试了好久也搞不出来可以copy多个文件,唉,苯啊。
Allblus 2006-04-21
  • 打赏
  • 举报
回复
谢谢。我试试!!!
老之 2006-04-21
  • 打赏
  • 举报
回复
uses ShellAPI;

procedure Copy(Source:string;Dest:string);
var SHFO:TShFileOpStruct;
begin
with SHFO do
begin
Wnd:=0;
wFunc:= FO_COPY;
pFrom:=PChar(Source+#0#0);
pTo:=PChar(Dest+#0#0);
fFlags:=FOF_NOCONFIRMATION;
fAnyOperationsAborted:=False;
end;
ShFileOperation(SHFO);
end;

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

procedure TForm1.ShellListView2DragDrop(Sender, Source: TObject; X,
Y: Integer);
var SourceName,DestName:string;
i:integer;
begin
SourceName:=ShellListView1.SelectedFolder.PathName;
DestName:=ExtractFilePath(ShellListView2.RootFolder.PathName)+'\'+ExtractFileName(SourceName);
Copy(SourceName,DestName);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ShellListView1.DragMode:=dmAutomatic;
ShellListView2.AutoRefresh:=True;
end;
hahafan 2006-04-21
  • 打赏
  • 举报
回复
设置ShellListview的DragMode为dmAutomatic,
在接受文件的ShellListview写OnDragOver和OnDragDrop事件
OnDragOver中确认接受,Accept := Source is TShellListView;
OnDragDrop中用SHFileOperation将选中文件拷过来即可
Allblus 2006-04-21
  • 打赏
  • 举报
回复
怎么顶都没人啊?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧