我如何向下降目标与我滴处理程序在德尔福工作? [英] How do I get IDropTarget to work with my Drop Handler in Delphi?

查看:143
本文介绍了我如何向下降目标与我滴处理程序在德尔福工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与我的2009年德尔福程序关联的文件扩展名。我一直在使用的命令行调用方法的文件名传递给我的Delphi程序,因此它可以被打开。

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.

不过,我发现,选择多个文件时,并点击它们全部一次,它会打开在我的程序的一个单独的实例每个文件。 <一href=\"http://stackoverflow.com/questions/3605903/how-can-i-get-my-file-association-to-open-multiple-files-in-a-single-program-inst\">I被问及这,显然,解决方案是使用另一之一两个Windows的方法:DDE或下降目标

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.

但DDE正在德precated和MSDN建议的方法下降目标。此外<一个href=\"http://stackoverflow.com/questions/3605903/how-can-i-get-my-file-association-to-open-multiple-files-in-a-single-program-inst/3606854#3606854\">Lars在回答我 Truijens说,可能下降目标更适合如果我已经运行拖放功能,这我。

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;

现在接受一个或多个文件,并打开它们,因为我需要。这是很老的code,从德尔福3本书,但它仍然似乎工作。

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.

我找不到任何文档上的任何地方如何在Delphi实现IDropHandler,特别是得到它与丢弃处理程序(上图),我使用的工作。

What I can't find is any documentation anywhere on how to implement IDropHandler in Delp and specifically to get it working with the Drop Handler (above) that I am using.

有人能告诉我如何使用IDropHandler使点击选定的文件和我的文件扩展名就会把它们传递给我滴处理程序和我的程序可以打开所有文件点击?

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?

推荐答案

此页面具有在Delphi实施下降目标的一个例子。 这里是另一个从绝地code格式化。但这个库可能会更好。它,除其他事项外,能够拖动并从Windows资源管理器下降,因此已经支持在下降目标的TDropHandler类。

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.

这篇关于我如何向下降目标与我滴处理程序在德尔福工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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