如何使用 IExecuteCommand 和动词在上下文菜单 shell 扩展中显示本地化文本和自定义图标?

How to show localized text and custom icons in context menu shell extensions using IExecuteCommand and verbs?

我正在考虑根据 IExecuteCommand 的新 Windows 7+ 方法开发上下文菜单 shell 扩展,如本博客 post 中所述:

Simplifying context menu extensions with IExecuteCommand

而不是我更熟悉的经典 IContextMenu 方法。

我对这个新方法有几个问题:

  1. 如何在自定义菜单项中显示本地化文本(例如,从资源中加载)?在旧模型中,这可以简单地在 IContextMenu::QueryContextMenu 实现中调用 InsertMenu,并传递从资源加载的字符串。

  2. 如何关联并显示 图标 与我的自定义菜单项?同样,这可以在旧的基于 IContextMenu 的模型中完成,例如调用 SetMenuItemBitmaps。菜单图标是否需要特定的图像格式?

IExecuteCommand 用于 shell 动词,这些动词是 registered statically in the Registry 并且具有与之关联的 "DelegateExecute"="{clsid}" 值。 static 动词的菜单文本取自为动词 注册的显示文本,并显示该文本按原样,它无法本地化,因为根本没有提供指定文本替代来源的选项。只有基于 IContextMenuIExplorerCommand 的真正 shell 扩展才可以选择本地化文本并为其自定义动词提供图标。 IExecuteCommand 不提供该功能

UPDATE:在 Windows XP 及更高版本中,static 动词的显示文本为 MUI-知道,因此您可以提供引用本地化资源的显示文本。这记录在案:

Using Registry String Redirection

Provide Resources for Shell Verb Action Strings

Action strings for certain verbs, for example, "open" and "edit", are shown in the pop-up menu displayed when the user right-clicks a file in Windows Explorer. Your application does not have to specify strings for common shell verbs, as the shell has its own MUI-enabled defaults for these verbs. However, you should provide localizable string resources for strings representing uncommon verbs.

On pre-Windows XP operating systems, strings for shell verbs in the registry are rendered using the following syntax, where verb specifies the actual verb name:

HKCR\<progid>\shell\<verb>
@ = <friendly-name>

Here's an example:

HKCR\Sample.app\shell\Disc
@ = "Disconnect"

On Windows XP and later, you can use a level of indirection to make an action string depend on user interface language. These operating systems support a MUIVerb value for definition of a MUI-compatible string. Here's an example of a registry entry for an uncommon verb:

HKCR\Sample.app\shell\Disc
@ = "Disconnect"
"MUIVerb" = "@%systemroot%\system32\sample.exe,-9875"

Your MUI application should also be able to register the old default value as a localizable string, as shown below:

HKCR\Sample.app\shell\Disc
@ = "@%systemroot%\system32\sample.exe,-9875"

Note Registration of the old default value is not recommended because it requires a different setup on Windows XP and later from the setup used on earlier operating systems.

AFAIK,您不能为 static 动词提供图标以显示在上下文菜单中。为此,您确实需要基于 IContextMenuIExplorerCommand 的 shell 扩展。