沈前卫 请进, 各位高手请进--关于剪贴板复制多个文件的问题(200分)

  • 主题发起人 主题发起人 pengyt
  • 开始时间 开始时间
P

pengyt

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
const FileName:string='c:/netlog.txt';
var
DataHandle: THandle;
DataPointer: PDROPFILES;
begin
DataHandle := GlobalAlloc(GMEM_DDESHARE or GMEM_MOVEABLE,SizeOf(DROPFILES)+2+Length(FileName));
DataPointer := PDROPFILES(GlobalLock(DataHandle));
FillChar(DataPointer^,SizeOf(DROPFILES)+2+Length(FileName),0);

DataPointer.pFiles:=SizeOf(DROPFILES);
DataPointer.pt:=Point(0,0);
DataPointer.fNC:=False;
DataPointer.fWide:=False;
Move(FileName[1],Pointer(Integer(DataPointer)+SizeOf(DROPFILES))^,Length(FileName));
GlobalUnlock(DataHandle);
OpenClipboard(Form1.Handle);
EmptyClipboard;
SetClipboardData(CF_HDROP, DataHandle);
CloseClipboard;
end;
以上是沈前卫 的回答(复制一个文件).
我的问题是,如果复制多个文件如何操作? 如果不是复制,而是移动又如何操作呢?
 
参考一下下面的代码, 得到文件名不就好办了么.

uses
clipbrd, shellapi;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
f: THandle;
buffer: Array [0..MAX_PATH] of Char;
i, numFiles: Integer;
begin
Clipboard.Open;
try
f:= Clipboard.GetAsHandle( CF_HDROP );
If f <> 0 Then Begin
numFiles := DragQueryFile( f, $FFFFFFFF, nil, 0 );
memo1.Clear;
for i:= 0 to numfiles - 1 do begin
buffer[0] := #0;
DragQueryFile( f, i, buffer, sizeof(buffer));
memo1.lines.add( buffer );
end;
end;
finally
Clipboard.close;
end;
end;
 
问题是怎样将多个文件名加进去? 以及移动文件(Ctrl+X)如何做?
 
加入多个文件名我知道怎么做了,谢谢.
那怎么移动文件呢? 现在的效果是复制
 
修改参数!
 
哪个参数?
 
有谁知道怎么移动文件?回答出来者另给200分
 
The MoveFile function renames an existing file or a directory (including all its
children).

BOOL MoveFile(

LPCTSTR lpExistingFileName, // address of name of the existing file
LPCTSTR lpNewFileName // address of new name for the file
);


Parameters

lpExistingFileName

Points to a null-terminated string that names an existing file or directory.

lpNewFileName

Points to a null-terminated string that specifies the new name of a file or directory.
The new name must not already exist. A new file may be on a different file system or
drive. A new directory must be on the same drive.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information,
call GetLastError.

Remarks

The MoveFile function will move (rename) either a file or a directory (including
all its children) either in the same directory or across directories. The one
caveat is that the MoveFile function will fail on directory moves when the
destination is on a different volume.

 
谢谢honestman,不过我要的不是这个:
让我把意思说清楚些:
当你在某个文件夹选定了文件后(一个或数个),按Ctrl-C或Ctrl-X,然后就算你
关掉这个文件夹,到另一个文件夹按Ctrl-V,那些你选定的文件就复制或移动
过来了.
我的问题是,怎样编程实现按Ctrl-C或Ctrl-X的效果,可以让我在关掉我的程序后
在别的文件夹按Ctrl-V也可以实现复制或移动文件的效果.
现在根据沈前卫和tseug的回答,复制的问题已经解决了(Ctrl-C),
怎样实现Ctrl-X的效果呢?请各位高手指教!

 
接受答案了.
 
后退
顶部