I have associated a file extension with my Delphi 2009 program. I have been using the command line call method to pass the filename to my Delphi program so it can be opened.
However, I found that when selecting multiple files, and clicking on them all at once, it opens each file in a separate instance of my program. I asked about this, and apparently the solution is to use one of the other two Windows methods: DDE or IDropTarget.
But DDE is being deprecated, and MSDN recommends the IDropTarget method. Also Lars Truijens in his answer to me, says that IDropTarget might fit better if I'm already running drag and drop capabilities, which I am.
Currently, this is my drop handler:
private
procedure WMDropFiles(var WinMsg: TMessage);
message wm_DropFiles;
procedure TLogoAppForm.FormShow(Sender: TObject);
begin
DragAcceptFiles(Handle, true);
end;
procedure TLogoAppForm.WMDropFiles(var WinMsg: TMessage);
// From Delphi 3 - User Interface Design, pg 170
const
BufSize = 255;
var
TempStr : array[0..BufSize] of Char;
NumDroppedFiles, I: integer;
Filenames: TStringList;
begin
NumDroppedFiles := DragQueryFile(TWMDropFiles(WinMsg).Drop, $ffffffff, nil, 0);
if NumDroppedFiles >= 1 then begin
Filenames := TStringList.Create;
for I := 0 to NumDroppedFiles - 1 do begin
DragQueryFile(TWMDropFiles(WinMsg).Drop, I, TempStr, BufSize);
Filenames.Add(TempStr);
end;
OpenFiles(Filenames, '');
Filenames.Free;
end;
DragFinish(TWMDropFiles(WinMsg).Drop);
WinMsg.Result := 0;
end;
It now accepts one or multiple files and will open them as I require. It is very old code, from a Delphi 3 book, but it still seems to work.
What I can't find is any documentation anywhere on how to implement IDropHandler in Delphi, and specifically to get it working with the Drop Handler (above) that I am using.
Can someone tell me how to use IDropHandler so that clicking on selected files with my file extension will pass them to my Drop Handler and my program can open all the files clicked on?