简体   繁体   中英

ShellExecute multiple files

I am wondering if it's possible to somehow use ShellExecute to open multiple files at once using the default verb handler. For example, if I have multiple mp3 files in a folder, I can select all of them, then right click and select "Play". This will bring up one instance of WMP (which is my default mp3 player) and will add all of the files I selected to the current playlist.

1) Is this accomplished using some standardized ShellExecute behavior?

2) Or is this done by first determining what the default program is and then supplying the list of files as arguments to that executable?

My goal is to be able to take a list of files and open them using the default verb with the default program (ideally without having to dig through the registry first).

Ie the equivalent of this, but for multiple files:

ShellExecute(NULL, NULL, the_file_to_open, NULL, NULL, SW_SHOWNORMAL);

No, ShellExecute can't do this. Instead, the way to do it is with IContextMenu .

Broadly speaking:

  • Bind to the parent folder with SHBindToObject
  • Query for a context menu for the files in question with IShellFolder::GetUIObjectOf
  • Initialise the context menu with IContextMenu::QueryContextMenu , passing the CMF_DEFAULTONLY flag
  • Invoke the default command with IContextMenu::InvokeCommand

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