How to gray out some context-menu options with an

2019-05-29 20:55发布

问题:

When implementing a context-menu shell extension using the IExecuteCommand approach (as described in this blog post), how can a given menu option be grayed out?

E.g. Suppose that the shell extension offers some menu options, and some of them should be grayed out basing on some state and conditions that the shell extension computes, for example: if the user right-clicks on a file and the shell extension detects that this file has some given properties, some of the shell extension context menu options should be grayed out.

How to do that using IExecuteCommand?

Or should another Windows Shell COM interface be used for that purpose?

回答1:

I have never tried this but you should be able to set CommandState­Handler (undocumented?) in your verb's key to a CLSID that implements IExplorerCommandState.

You might also think about implementing IExplorerCommand instead of IExecuteCommand+IExplorerCommandState...

You can also hide verbs based on a query to the property system with the AppliesTo value.