Copiar um arquivo para a área de transferência pelo delphi
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
| uses
ShlObj, ClipBrd;
procedure CopyFileToClipboard(pFilePath: string);
var
D: PDropFiles;
H: THandle;
L: Integer;
S: Integer;
P: Integer;
begin
Assert(not(pFilePath.Trim.IsEmpty), 'pFilePath não pode ser vazia!');
L := pFilePath.Length;
S := SizeOf(Char);
P := SizeOf(TDropFiles);
H := GlobalAlloc($2000 or 2 or $40, P + ((L + 2) * S));
Assert(H > 0, 'Não foi possível alocar memória requisitada.');
try
D := GlobalLock(H);
Assert(Assigned(D), 'Não foi possível acessar a memória alocada.');
try
D^.pFiles := P;
D^.fWide := True;
Move(pFilePath[1], (PByte(D) + P)^, (L * S));
finally
GlobalUnlock(H);
end;
Clipboard.SetAsHandle(15, H);
except
GlobalFree(H);
end;
end; |
uses
ShlObj, ClipBrd;
procedure CopyFileToClipboard(pFilePath: string);
var
D: PDropFiles;
H: THandle;
L: Integer;
S: Integer;
P: Integer;
begin
Assert(not(pFilePath.Trim.IsEmpty), 'pFilePath não pode ser vazia!');
L := pFilePath.Length;
S := SizeOf(Char);
P := SizeOf(TDropFiles);
H := GlobalAlloc($2000 or 2 or $40, P + ((L + 2) * S));
Assert(H > 0, 'Não foi possível alocar memória requisitada.');
try
D := GlobalLock(H);
Assert(Assigned(D), 'Não foi possível acessar a memória alocada.');
try
D^.pFiles := P;
D^.fWide := True;
Move(pFilePath[1], (PByte(D) + P)^, (L * S));
finally
GlobalUnlock(H);
end;
Clipboard.SetAsHandle(15, H);
except
GlobalFree(H);
end;
end;
Para usar basta chamar assim:
1
2
3
4
| procedure TForm1.Button1Click(Sender: TObject);
begin
CopyFileToClipboard('C:\Unit1.pas');
end; |
procedure TForm1.Button1Click(Sender: TObject);
begin
CopyFileToClipboard('C:\Unit1.pas');
end;
Depois basta ir no diretório de destino e colar (CTRL + V)
-
Ivan Cesar
-
4.534 views
- 0 comentários
- 15 de julho de 2016
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo