应该是通过剪贴板吧
一、把文件复制到Clipboard,这样就可以直接粘贴到桌面了。(这个在网上找的,没试过不知有没用)
uses shlobj,activex,clipbrd;
procedure Tform1.copytoclipbrd(var FileName:string);
var
FE:TFormatEtc;
Medium: TStgMedium;
dropfiles
DropFiles;
pFile
Char;
begin
FE.cfFormat := CF_HDROP;
FE.dwAspect := DVASPECT_CONTENT;
FE.tymed := TYMED_HGLOBAL;
Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_ZEROINIT, SizeOf(TDropFiles)+length(FileName)+1);
if Medium.hGlobal<>0 then begin
Medium.tymed := TYMED_HGLOBAL;
dropfiles := GlobalLock(Medium.hGlobal);
try
dropfiles^.pfiles := SizeOf(TDropFiles);
dropfiles^.fwide := False;
longint(pFile) := longint(dropfiles)+SizeOf(TDropFiles);
StrPCopy(pFile,FileName);
Inc(pFile, Length(FileName)+1);
pFile^ := #0;
finally
GlobalUnlock(Medium.hGlobal);
end;
Clipboard.SetAsHandle(CF_HDROP,Medium.hGlobal);
end;
end;
二、当用户在桌面上复制了一个文件以后,要粘贴就简单了
uses
Clipbrd, ShellAPI;
procedure GetClipFileNames(Strings: TStrings);
var
CHandle: Cardinal;
I, Count: Integer;
StrBuf: array[0..MAX_PATH - 1] of Char;
begin
CHandle := Clipboard.GetAsHandle(CF_HDROP);
I := -1;
Count := DrayQueryFile(CHandle, I, StrBuf, 0);
for I := 0 to Count - 1 do
if DrayQueryFile(CHandle, I, StrBuf, MAX_PATH) > 0 then
Strings.Add(StrBuf);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Clipboard.HasFormat(CF_HDROP) then //判断是不是复制了文件在Clipboard
GetClipFileNames(Memo1.Lines);
end;