我把文件复制到了剪粘板,问题是只能实现复制,怎么实现剪切啊,下面的代码只能复制,以下代码是网上找的
procedure CopyFilesToClipboard(FileList: string);
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: Integer;
begin
iLen := Length(FileList) + 2;
FileList := FileList + #0#0;
hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT,
SizeOf(TDropFiles) + iLen);
if (hGlobal = 0) then raise Exception.Create('没有找到');
begin
DropFiles := GlobalLock(hGlobal);
DropFiles^.pFiles := SizeOf(TDropFiles);
Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
GlobalUnlock(hGlobal);
Clipboard.SetAsHandle(CF_HDROP, hGlobal);
sendmessage(hGlobal,WM_CUT,0,0);
end;
end;
procedure CopyFilesToClipboard(FileList: string);
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: Integer;
begin
iLen := Length(FileList) + 2;
FileList := FileList + #0#0;
hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT,
SizeOf(TDropFiles) + iLen);
if (hGlobal = 0) then raise Exception.Create('没有找到');
begin
DropFiles := GlobalLock(hGlobal);
DropFiles^.pFiles := SizeOf(TDropFiles);
Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
GlobalUnlock(hGlobal);
Clipboard.SetAsHandle(CF_HDROP, hGlobal);
sendmessage(hGlobal,WM_CUT,0,0);
end;
end;
用getClipboardData()函数。procedure paste(path: string);
//粘贴
var
cDropEffect: UINT; // 注册类别
hDropEffect: HGLOBAL; // 操作类型
pDropEffect: PDWORD;
begin
try
if path[length(path)] <> '\' then
path := path + '\'; if Clipboard.HasFormat(CF_HDROP) then
begin
Clipboard.Open;
//从剪贴板取回文件名称
f := Clipboard.GetAsHandle(CF_HDROP);
if f <> 0 then
begin
numFiles := DragQueryFile(f, $FFFFFFFF, nil, 0);
for i := 0 to numFiles - 1 do
begin
DragQueryFile(f, i, FFileName, SizeOf(FFileName));
s := s + FFileName + #0;
end;
end;
cDropEffect := RegisterClipboardFormat('Preferred DropEffect');
hDropEffect := getClipboardData(cDropEffect);
pDropEffect := GlobalLock(hDropEffect);
GlobalUnlock(hDropEffect);
Clipboard.Close; if pDropEffect^ = DROPEFFECT_MOVE then
这了是你的操作
end; finally end;
end;