1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
| function TForm1.WintFileOpen:Boolean; begin try AssignFile(wintf,wintfile); Rewrite(wintf,1); Except
end; end;
function TForm1.WintFileWriteBinary(t:string;l:integer):Boolean; begin try if l > 0 then BlockWrite(wintf,t[1],l); Result:=true; except Result:=false; end; end;
function TForm1.WintFileClose:Boolean; begin CloseFile(wintf); Result:=true; end;
procedure TForm1.GetFilesFromClipboard; var handle:THandle; handleCont:THandle; size, sizeCont:dWord; f:File; Result, aResult, ResultCont:String; Des:TFileDescriptor; Grp:^TFileGroupDescriptor; j, Pos:Integer; nFiles:Integer; begin CF_FILECONTENTS := RegisterClipboardFormat('FileContents'); CFSTR_FILECONTENTS := RegisterClipboardFormat('CFSTR_FILECONTENTS'); CF_FILEGROUPDESCRIPTOR := RegisterClipboardFormat('FileGroupDescriptor'); if clipboard.HasFormat(CF_FILECONTENTS) then begin Clipboard.Open; try handle:= Clipboard.GetAsHandle(CF_FILEGROUPDESCRIPTOR); if handle<>0 then size:=GlobalSize(Handle); if size <> 0 then begin setString(Result, PChar(GlobalLock(Handle)), size); Grp:=Pointer(Result); nFiles:=Grp.cItems; handleCont:= Clipboard.GetAsHandle(CF_FILECONTENTS); Pos:=0; if handleCont<>0 then sizeCont := GlobalSize(HandleCont); if sizeCont<>0 then begin SetString(ResultCont, PChar(GlobalLock(HandleCont)), sizeCont); for j := 1 to nFiles do begin System.Move(Result[SizeOf(DWORD)+1+(j-1)*SizeOf(TFileDescriptor)], Des, SizeOf(TFileDescriptor)); aResult:=copy(ResultCont,Pos,sizeCont); ShowMessage(des.cFileName); Wintfile:='C:\Temp\Test.doc'; WintFileOpen; WintFileWriteBinary(aResult,sizeCont); WintFileClose; end; GlobalUnlock(handle); end; end; finally Clipboard.Close; end; end; end; |