procedure CopyFilesToClipboard(FileList: string);
var
DropFiles: PDropFiles;
hGlobal: Thandle;
iLen: Integer;
begin
iLen := Length(FileList) * SizeOf(Char) + 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('Could not allocate memory.');
begin
DropFiles := GlobalLock(hGlobal);
DropFiles^.pFiles := SizeOf(TDropFiles);
DropFiles^.pt.X := 0;
DropFiles^.pt.Y := 0;
DropFiles^.fNC := False;
DropFiles^.fWide := true;
Move(FileList[1], (PAnsiChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
GlobalUnlock(hGlobal);
ClipBoard.SetAsHandle(CF_HDROP, hGlobal);
end;
end;
CopyFilesToClipboard('D:\设计师结算\2019年\已结算账单\123.txt');
procedure CutOrCopyFiles(FileList: AnsiString; bCopy: Boolean);
type
PDropFiles = ^TDropFiles;
TDropFiles = record
pfiles: DWORD;
pt: TPoint;
fNC: BOOL;
fwide: BOOL;
end;
const
DROPEFFECT_COPY = 1;
DROPEFFECT_MOVE = 2;
var
hGblFileList: hGlobal;
pFileListDate: Pbyte;
HandleDropEffect: UINT;
hGblDropEffect: hGlobal;
pdwDropEffect: PDWORD;
iLen: Integer;
begin
iLen := Length(FileList) + 2;
FileList := FileList + #0#0;
hGblFileList := GlobalAlloc(GMEM_ZEROINIT or GMEM_MOVEABLE or GMEM_SHARE,
SizeOf(TDropFiles) + iLen);
pFileListDate := GlobalLock(hGblFileList);
PDropFiles(pFileListDate)^.pfiles := SizeOf(TDropFiles);
PDropFiles(pFileListDate)^.pt.Y := 0;
PDropFiles(pFileListDate)^.pt.X := 0;
PDropFiles(pFileListDate)^.fNC := False;
PDropFiles(pFileListDate)^.fwide := False;
Inc(pFileListDate, SizeOf(TDropFiles)); // ?????ó??
CopyMemory(pFileListDate, @FileList[1], iLen);
GlobalUnlock(hGblFileList);
HandleDropEffect := RegisterClipboardFormat('Preferred DropEffect ');
hGblDropEffect := GlobalAlloc(GMEM_ZEROINIT or GMEM_MOVEABLE or GMEM_SHARE,
SizeOf(DWORD));
pdwDropEffect := GlobalLock(hGblDropEffect);
if (bCopy) then pdwDropEffect^ := DROPEFFECT_COPY
else pdwDropEffect^ := DROPEFFECT_MOVE;
GlobalUnlock(hGblDropEffect);
if OpenClipboard(0) then
begin
EmptyClipboard();
SetClipboardData(HandleDropEffect, hGblDropEffect);
SetClipboardData(CF_HDROP, hGblFileList);
CloseClipboard();
end;
end;
procedure CopyFileClipbrd(const FName: string);
begin
CutOrCopyFiles(AnsiString(FName), True);
end;
CopyFileClipbrd('H:\HEI\注册机\Rookie.dat');
来源:CSDN
作者:小小de巫师
链接:https://blog.csdn.net/gfuchao/article/details/103595874