How to open multiple files with Delphi program inv

2019-04-02 01:27发布

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

4条回答
祖国的老花朵
2楼-- · 2019-04-02 01:52

I note that you are only registering it with %1.

I would try %1 %2 %3 %4 %5 etc in the registry.

I have never played with shell extensions to see what else might be making this fail. All I've done is registered file associations and they behave exactly as I would expect.

查看更多
不美不萌又怎样
3楼-- · 2019-04-02 02:01

Besides everything else, you should use %l instead of %1. That way your program will get a full (long) name of the file, not the short (DOS 8.3) one.

EDIT: An answer to Rob's question in comments

It seems that it's almost impossible to search for '%l' and '%1' (including percent sign) either using Google or MSDN search. :( However, I found a pretty good description in The Old New Thing - '%1' autodetects whether your program supports long file names and passes either short or long name. It seems that all modern systems pass long name unless your exe cannot be found (at least that's how I understand the Raymond's expose).

If you scroll further down in the comments (search for '%l' on the page) you'll find a list of all supported parameters, taken from some page that doesn't exist anymore (but I found an old copy in the Internet Archive). That page doesn't include no reference to Microsoft documentation either, so I can't give you an authoritative link :(

Rob, thank's for asking - I now know more about %1/%l than before :) +1 for that.

查看更多
Fickle 薄情
4楼-- · 2019-04-02 02:03

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-04-02 02:08

Not sure what you really want. But you can find the number of parameters with:

ParamCount;

Each param is then found with

ParamStr(1);
ParamStr(2);
ParamStr(3);

Until ParamCount.

查看更多
登录 后发表回答