Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Duplicated menu items in Folder pane #5

Closed
johnstevenson opened this issue Nov 1, 2013 · 2 comments
Closed

Duplicated menu items in Folder pane #5

johnstevenson opened this issue Nov 1, 2013 · 2 comments

Comments

@johnstevenson
Copy link
Member

On Vista duplicated Git menu entries are added when you right-click a folder in the Folders pane
git-cheetah
This is because the Shell calls the handler for the Directory\Background progid first (with a folder pidl), then calls it again for the other entries with a data object. So the trick is to check if the Git menu has already been written.

One way you can do this is by using InsertMenuItem on all menu entries and adding a unique identifier (your module handle, for example) to the dwItemData member of the item structure.

    MENUITEMINFO mii = { sizeof(mii) };
    mii.cbSize = sizeof(MENUITEMINFO);
    mii.fMask = MIIM_STRING |  MIIM_ID | MIIM_DATA; // add MIIM_SUBMENU for a sub menu
    mii.dwItemData = (ULONG_PTR) hInstance;
    ...
    InsertMenuItem(hMenu, menuIndex, TRUE, &mii)

Then in the QueryContextMenu function you can check if any menu item has this value and act accordingly:

    MENUITEMINFO mii = { sizeof(mii) };
    mii.cbSize = sizeof(MENUITEMINFO);
    mii.fMask = MIIM_DATA;

    // get the number of existing menu entries
    int count = GetMenuItemCount(hMenu);

    for (int i = 0; i < count; ++i)
    {
        // get the item data
        GetMenuItemInfo(hMenu, i, TRUE, &mii);

        if (mii.dwItemData == (ULONG_PTR) hInstance)
        {
             // menu already written   
            return S_OK;
        }
    }

    // menu not written
    ...

I had the same problem in an extension I was working on, and solved it with this solution.

@dscho
Copy link
Member

dscho commented Nov 1, 2013

That looks like half a pull request to me! Well done! How about going the full nine yards and make it a proper pull request? Then you'd get eternal fame by being in the elite list of contributors... ;-)

@dscho
Copy link
Member

dscho commented Dec 30, 2013

Fixed in #7.

@dscho dscho closed this as completed Dec 30, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants