简体   繁体   中英

How to pass several files at once to my registered application?

In a Delphi 10.4.2 win-32 VCL Application associated with graphic file formats in Windows 10, I get parameter files selected in Windows File Explorer. Here I watch the files passed to my app right after Application.Initialize; :

CodeSite.Send('AppInstances: ParamCount', ParamCount);

When I select ONE file in Explorer and then press the ENTER key, this file gets loaded in my application. So far so good.

But when I select THREE files in Explorer and then press the ENTER key, my app gets started THREE times each time with ONE of the 3 file parameters:

在此处输入图像描述

Is it possible that Explorer would start my app only ONCE and pass the 3 selected files at once to my app when I press the Enter key?

On Windows 7 and later 1 , you can register a MultiSelectModel value (either Document or Player ) with your file association verb(s) in the Registry. This is the easiest way to allow Explorer to send multiple files at a time to a single instance of your app, such as in separate command-line parameters.

1: I don't know exactly when this feature was first introduced.

Prior to MultiSelectModel , other ways to handle this included:

  • implementing the IDropTarget interface in your app, and then registering the DropTarget with your file association verb(s). The Shell can then construct an IDataObject containing information about the files(s), and pass it to your IDropTarget implementation (also seethis article ). This is the preferred method, as it does not suffer from limitations that other methods have (including MultiSelectModel ,), and it allows for more flexibility as the same IDropTarget implementation can accept multiple files executed in Explorer, files dropped onto your app's window, even dropped onto the app's .EXE file itself. It is just a matter of registering the same IDropTarget with the appropriate APIs.

  • Implementing a DDE server in your app, and then registering the server with your file association verb(s). The Shell can then start a DDE conversation with your app and send the file paths over to it using your specified command(s).

  • just accepting the Shell starting a separate process for each file. Before your app creates its UI, have its startup code check for a file path on its command-line, and if found then look for another instance of your app already running, and if found then use an Inter-Process Communication mechanism of your choosing (ie, WM_COPYDATA , named pipe, socket, mailslot, etc) to send the file path to that existing instance, and then exit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM