Author: Jonas Bilinkevicius
I would like to be able to go to Windows Explorer, select a series of files, and
then allow the user to "Paste" these files into my application. I simply need a
list of the file names that were copied to the clipboard. Anyone know how to access
this list?
Answer:
You can use OLE Drag & Drop, but since Explorer creates a standard CF_HDROP
clipboard block you can also hack it this way:
1 uses2 clipbrd, shellapi;
3 4 {$R *.DFM}5 6 procedure TForm1.Button1Click(Sender: TObject);
7 var8 f: THandle;
9 buffer: array[0..MAX_PATH] of Char;
10 i, numFiles: Integer;
11 begin12 Clipboard.Open;
13 try14 f := Clipboard.GetAsHandle(CF_HDROP);
15 if f <> 0 then16 begin17 numFiles := DragQueryFile(f, $FFFFFFFF, nil, 0);
18 memo1.Clear;
19 for i := 0 to numfiles - 1 do20 begin21 buffer[0] := #0;
22 DragQueryFile(f, i, buffer, sizeof(buffer));
23 memo1.lines.add(buffer);
24 end;
25 end;
26 finally27 Clipboard.close;
28 end;
29 end;