How do I make sure that my shell extension is at the top of the context menu?

Raymond Chen

A customer wanted the items for their context menu shell extension to appear at the very top of the context menu. They did this by ignoring the recommended insertion point passed to the IContext­Menu::Query­Context­Menu function and just inserting their items at the top anyway:

HRESULT MyContextMenu::QueryContextMenu(
    HMENU hmenu, UINT indexMenu,
    UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
    // Insert at the top (position 0), ignoring the indexMenu
    InsertMenuItem(hMenu, 0, TRUE, &mii);

However, they found that this didn’t work. Their context menu item showed up in the middle.

Well, sure, their context menu extension broke the rules and put their menu item at the top, but that just gets them to the top of the context menu so-far. But there are other shell extensions, and they may end up going on top of yours. And of course there’s the shell itself, which has final say over where things go, and it might decide to put things on top of yours as well.

At the end of the day, it’s the context menu host that decides where the menu items go. If you break the rules, you may be able to trick the host for a little while, but you’re living on borrowed time.

(And of course there’s also the question “What if two programs did this?”


Discussion is closed.

Feedback usabilla icon