How can I know if my context menu extension was called from the top-level menu or "Show More Options"?

David Izada Rodriguez 46 Reputation points
2022-12-12T16:08:20.99+00:00

On Windows 11 "Show More Options" context menu, my extension shows a two-level menu (dynamically, depending on the selected files or folders).
On the top-level context menu, I can only show a single-level menu.
Because of this limitation, I moved the submenu items under a separator.
Instead of reporting the item as having sub-commands, I returned ECF_ISSEPARATOR.
Each sub-command is now under the separator.

But I would like to keep the two-level menu under "Show More Options."

I'm implementing the IExplorerCommand interface, but I will need another to receive additional information about the context of the call (to identify if the caller is trying to render the menu at the top level or under "Show More Options").

How can I do it?

Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

1 answer

Sort by: Most helpful
  1. David Izada Rodriguez 46 Reputation points
    2022-12-14T14:53:11.567+00:00

    I couldn't find an official API to solve this, so I found an alternative solution.

    The extension exposes the IExplorerCommand interface, but it can be used differently.
    File Explorer calls extension methods in a different sequence when building the top-level context and the "Show More Options" menu.
    Top-Level Menu:

    Load(Parent = nil, Cmd)

    1. Cmd.GetState(ItemArray)
    2. Cmd.GetTitle(ItemArray)
    3. Cmd.GetIcon(ItemArray)
    4. Cmd.GetFlags
    5. while Cmd.Enum.Next = S_OK do Cmd.Load(Cmd, ItemArray)

    Show More Options Menu:

    Load(Parent = nil, Cmd)

    1. Cmd.SetSelection(ItemArray)
    2. Cmd.GetFlags
    3. Cmd.GetCanonicalName
    4. Cmd.GetToolTip
    5. Cmd.GetTitle(ItemArray)
    6. Cmd.GetIcon(ItemArray)
    7. Cmd.GetState(ItemArray)
    8. while Cmd.Enum.Next = S_OK do Cmd.Load(Cmd, ItemArray)

    We can distinguish between the top-level menu and "Show more options" by monitoring the first call from File Explorer.
    It is a fragile solution, but it works with current Windows 11 builds (I tried the official version and the latest Insider Preview).

    I hope this helps other developers facing the same issue.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.