如何用Delphi程序打开多个文件通过shell打开调用 [英] How to open multiple files with Delphi program invoked via shell open

查看:301
本文介绍了如何用Delphi程序打开多个文件通过shell打开调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用:

  if ParamStr(1)<>'%1'then 
begin
address.Text:= ParamStr(1);
autoconfigfile;
end;

可以通过文件关联来获取用于打开文件的文件名称。 / p>

我现在想开发对多个文件操作的能力。
I.e如果我选择5个文件,右键单击并选择打开加密系统。
我有注册表项:

  reg.OpenKey('* \shell\Encrypt\command' ,true); 
reg.WriteString('','C:\Program Files\EncryptionSystem\EncryptionSystem.exe%1');
reg.CloseKey;

向所有文件添加右键打开功能。

  • 每个文件的路径名
  • / li>


    解决方案

    如果您尝试同时打开多个文件,



    现在根据您最近的问题进行判断



    如何告诉我的程序的一个实例是否正在运行?

    如何将字符串从我的Delphi程序的一个实例发送到另一个?



    你不希望允许多个程序实例,因此您需要重新考虑该设计决策,或者实现第二个问题的答案中列出的方法之一,将程序的辅助实例的命令行参数发送到第一个实例。请注意,计时在这里很重要,因为第一个实例可能还没有准备好从其他实例接收数据。特别是使用主窗体的窗口句柄的解决方案,或者某种形式的基于管道或文件的通信机制将涉及等待第一实例准备就绪。因此,简单地允许程序的多个实例可能更容易。



    您可能还想查看此Microsoft知识库条目或搜索有关 DDE Execute 命令的更多信息。



    修改:您还可以在注册表项中尝试使用%*而不是%1,详情请参见旧新功能注释 gabr的答案提到。我没有测试这个,但它看起来可以工作。


    I am currently using:

    if ParamStr(1)<>'%1' then
    begin
      address.Text:=ParamStr(1);
      autoconfigfile;
    end;
    

    to pick up the name of the file that was used to open the file with via file association.

    I now want to develop the ability to operate on multiple files. I.e. if I select 5 files and right click and select open with "EncryptionSystem". I have the registry entry:

      reg.OpenKey('*\shell\Encrypt\command', true);
      reg.WriteString('','C:\Program Files\EncryptionSystem\EncryptionSystem.exe "%1"');
      reg.CloseKey;
    

    To add a right click open ability to all files. I would then want the ability to detect

    1. how many files
    2. the pathname of each file

    解决方案

    If you try to open multiple files at once you will generally get multiple instances of the registered program, each opening one of the files.

    Now judging from your recent questions

    How do i tell if one instance of my program is running?
    How do I send a string from one instance of my Delphi program to another?

    you do not wish to allow multiple instances of the program, so you will need to either reconsider that design decision, or implement one of the ways outlined in the answers to the second question to send the command line parameter of the secondary instances of your program to the first instance. Please note that timing is important here, because the first instance may well not yet be ready to receive the data from the other instances. Especially with solutions using the window handle of the main form, or some form of pipe- or file-based communication mechanism will involve waiting for the first instance to be ready. It may therefore be much easier to simply allow multiple instances of the program.

    You may also want to look into this Microsoft Knowledge Base entry or search for more information about the DDE Execute command.

    Edit: You could also try with "%*" instead of "%1" in the registry key, as detailed in the "Old New Thing" comment the answer by gabr mentioned. I haven't tested this, but it looks like it could work.

    这篇关于如何用Delphi程序打开多个文件通过shell打开调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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