I have associated the file extension with my Delphi 2009 program. I use the command line invocation method to pass the file name to my Delphi program so that it can be opened.
However, I found that when I select several files and click on them at the same time, it opens each file in a separate copy of my program. I asked about this , and apparently the solution is to use one of the two other Windows methods: DDE or IDropTarget .
But DDE is deprecated, and MSDN recommends the IDropTarget method. Lars Truyens also says in his answer to me that IDropTarget can fit better if I already have the drag and drop capabilities that I have.
This is currently 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;
Now it takes one or more files and opens them as needed. This is very old code from the Delphi 3 book, but it still works.
What I cannot find is any documentation anywhere on how to implement IDropHandler in Delphi, and in particular, to make it work with the Drop handler (above) that I use.
Can someone tell me how to use IDropHandler to click on selected files with my file extension will pass them to my Drop handler and my program can open all the files that I clicked on?
delphi drag-and-drop associations registry
lkessler
source share