如何让IDropTarget与Delphi中的Drop Handler配合使用? [英] How do I get IDropTarget to work with my Drop Handler in Delphi?

查看:219
本文介绍了如何让IDropTarget与Delphi中的Drop Handler配合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将文件扩展名与我的Delphi 2009程序相关联。我一直在使用命令行调用方法将文件名传递给我的Delphi程序,以便可以打开它。



但是,我发现当选择多个文件时,同时点击它们,它会在我的程序的单独实例中打开每个文件。 我问过这个,显然解决方案是使用其中一个其他两种Windows方法:DDE或IDropTarget



但DDE已被弃用,MSDN推荐使用IDropTarget方法。另外 Lars Truijens在对我的回答中表示,如果我已经在运行拖放功能,IDropTarget可能会更好,



目前,这是我的放置处理程序:

  private 
procedure WMDropFiles(var WinMsg:TMessage);
message wm_DropFiles;

程序TLogoAppForm.FormShow(发件人:TObject);
begin
DragAcceptFiles(Handle,true);
结束

程序TLogoAppForm.WMDropFiles(var WinMsg:TMessage);
//来自Delphi 3 - 用户界面设计,第170页
const
BufSize = 255;
var
TempStr:数组[0..BufSize]的Char;
NumDroppedFiles,I:integer;
文件名:TStringList;
begin
NumDroppedFiles:= DragQueryFile(TWMDropFiles(WinMsg).Drop,$ ffffffff,nil,0);
如果NumDroppedFiles> = 1然后开始
文件名:= TStringList.Create;
为I:= 0到NumDroppedFiles - 1 do begin
DragQueryFile(TWMDropFiles(WinMsg).Drop,I,TempStr,BufSize);
Filenames.Add(TempStr);
结束
OpenFiles(Filenames,'');
Filenames.Free;
结束
DragFinish(TWMDropFiles(WinMsg).Drop);
WinMsg.Result:= 0;
结束

它现在可以接受一个或多个文件,并根据需要打开它们。这是非常旧的代码,从Delphi 3书,但它似乎仍然工作。



我找不到任何关于如何实现IDropHandler的任何文档Delphi,并专门让它与我正在使用的Drop Handler(上面)一起使用。



有人可以告诉我如何使用IDropHandler,以便点击所选文件我的文件扩展名将传递给我的Drop Handler,我的程序可以打开所有点击的文件?

解决方案

这个页面有一个在Delphi中实现IDropTarget的例子。 这里是Jedi Code Formatter的另一个。但是这个图书馆可能会更好。除其他外,它可以从Windows资源管理器中拖放,因此已经在TDropHandler类中支持IDropTarget。


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?

解决方案

This page has an example of implementing IDropTarget in Delphi. Here is another from Jedi Code Formatter. But this library might be even better. It, amongst other things, enables dragging and dropping from Windows Explorer and therefore already supports IDropTarget in the TDropHandler class.

这篇关于如何让IDropTarget与Delphi中的Drop Handler配合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆