Shell执行多个文件 [英] ShellExecute multiple files

查看:26
本文介绍了Shell执行多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能以某种方式使用 ShellExecute 使用默认动词处理程序一次打开多个文件.例如,如果我在一个文件夹中有多个 mp3 文件,我可以选择所有这些文件,然后右键单击并选择播放".这将打开一个 WMP 实例(这是我的默认 mp3 播放器)并将我选择的所有文件添加到当前播放列表中.

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) 这是使用一些标准化的 ShellExecute 行为完成的吗?

1) Is this accomplished using some standardized ShellExecute behavior?

2) 还是先确定默认程序是什么,然后提供文件列表作为该可执行文件的参数?

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

推荐答案

不,ShellExecute 不能这样做.相反,这样做的方法是使用 IContextMenu.

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

概括地说:

  • 使用 SHBindToObject
  • 绑定到父文件夹
  • 使用 IShellFolder::GetUIObjectOf
  • 查询相关文件的上下文菜单
  • 使用 IContextMenu::QueryContextMenu 初始化上下文菜单,传递 CMF_DEFAULTONLY 标志
  • 使用 IContextMenu::InvokeCommand
  • 调用默认命令
  • 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

这篇关于Shell执行多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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