pqvst
pqvst

Reputation: 4444

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).

I.e. the equivalent of this, but for multiple files:

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

Upvotes: 2

Views: 1233

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37202

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

Upvotes: 8

Related Questions