Post by SanneDoes someone has an example how to drag files from explorer to a control,
like a listbox or a treeview? So not to the main app, but just the control.
It's pretty simple to register as a receiver. Just call
DragAcceptFiles. But then you need to "teach" the control what to do
when something is dropped on it by handling the WM_DROPFILES message.
Depending on what you expect the control to do, that can be easy or
complicated, but getting the files is simple:
procedure TSomething.WMDropFiles(var Msg: TWMDropFiles);
{ Notification that some files have been dropped on us }
var
BuffSize: Integer;
DropHandle: THandle;
FileCount: Integer;
FileName: string;
FileNo: Integer;
begin
{ Tell Windows we handled it }
with Msg do begin Result := 0; DropHandle := Drop; end;
{ Get the count of files }
FileCount := DragQueryFile(DropHandle, $FFFFFFFF, nil, 0);
{ For each file dropped onto us ... }
for FileNo := 0 to FileCount - 1 do
begin
{ Ask how big the name is }
BuffSize := DragQueryFile(DropHandle, FileNo, nil, 0) + 1;
{ Allocate space for it }
SetLength(FileName, BuffSize);
{ Get the name }
DragQueryFile(DropHandle, FileNo, @FileName[1], BuffSize);
{ Nuke the trailing NUL }
SetLength(FileName, Pos(#0, FileName) - 1);
{ Do "something" with FileName }
//
end;
{ Release the buffer }
DragFinish(DropHandle);
end;
Good luck.
Kurt