Author: Tomas Rutkauskas
I need to have the filename and directory of the file which is in the clipboard.
For example: In the Explorer I select a file, press ctrl+c and in my application I
would like copy or do anything with it.
Answer:
1 procedure TMainForm.Button1Click(Sender: TObject);
2 var
3 hDrop: THandle;
4 cnt, i: Integer;
5 filename: array[0..MAX_PATH - 1] of Char;
6 begin
7 if ClipBoard.HasFormat(CF_HDROP) then
8 begin
9 hDrop := ClipBoard.GetAsHandle(CF_HDROP);
10 cnt := DragQueryFile(hDrop, $FFFFFFFF, nil, 0);
11 Memo.Clear;
12 Memo.Lines.Add(Format('Found %d files:', [cnt]));
13 for i := 0 to cnt - 1 do
14 begin
15 DragQueryFile(hDrop, i, @filename, MAX_PATH);
16 Memo.lines.Add(Format('%2d: %s', [i + 1, filename]));
17 end;
18 end
19 else
20 MessageDlg(' No filename in clipboard!', mtInformation, [mbOk], 0);
21 end;
|