2

I need my app to create right-click context menu items (and sub-menu items). I'm not concerned with the code - but I don't know how to make sub-menu items in the registry. It's not as logical as one would expect.

I've searched countless times already and have officially given up searching for now.

I know that we can create a context menu item using regedit.exe by going to the shell key and adding a new one but how do I create sub menu items like 7zip for example?

Shows newly-created context menu item in the windows registry

2 Answers 2

4

Take a look at this Code-Project article: Add a context menu to the Windows Explorer. It seems to be very easy by using the Registry class provided by the .net framework.

Some more advanced/better solution seems to be using some library such as: SharpShell

EDIT

Please take a look at: .NET Shell Extensions - Adding submenus to Shell .

Ths part should solve your problem:

// <summary>
// Creates the context menu when the selected item is a folder.
// </summary>
protected void MenuDirectory()
{
    ToolStripMenuItem MainMenu;
    MainMenu = new ToolStripMenuItem
    {
        Text = "MenuDirectory",
        Image = Properties.Resources.Folder_icon
    };

            ToolStripMenuItem SubMenu1;
            SubMenu1 = new ToolStripMenuItem
            {
                Text = "DirSubMenu1",
                Image = Properties.Resources.Folder_icon
            };

            var SubMenu2 = new ToolStripMenuItem
            {
                Text = "DirSubMenu2",
                Image = Properties.Resources.Folder_icon
            };
            SubMenu2.DropDownItems.Clear();
            SubMenu2.Click += (sender, args) => ShowItemName();

                    var SubSubMenu1 = new ToolStripMenuItem
                    {
                        Text = "DirSubSubMenu1",
                        Image = Properties.Resources.Folder_icon
                    };
                    SubSubMenu1.Click += (sender, args) => ShowItemName();

    // Let's attach the submenus to the main menu
    SubMenu1.DropDownItems.Add(SubSubMenu1);
    MainMenu.DropDownItems.Add(SubMenu1);
    MainMenu.DropDownItems.Add(SubMenu2);

    menu.Items.Clear();
    menu.Items.Add(MainMenu);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but neither of those articles address the issues in my question. I already know how to create context menu items. I just don't know how to create sub menu items.
@popshuvit added some more. Thank you for that hint :)
2

You have to create a command folder for example Archive, with two commands: A and B.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Archive]
"MUIVerb"="Archive"
"SubCommands"="Windows.A;Windows.B"

The * in key means this menu shows up at right click on any file. If you want it only at the *.7z files, use HKEY_CLASSES_ROOT\.7z\shell\Archive. The value of MUIVerb will be the name of menu item. If you named the MUIVerb to 7-Zip, the right click menu will contains two 7-Zip items.

Then create the commands there:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.A]
"MUIVerb"="Command name of A"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.A\command]
@="notepad.exe \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.B]
"MUIVerb"="Command name of B"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.B\command]
@="notepad.exe \"%1\""

In this example, you get an Archive menuitem, with cascaded two command, whats open the current file with notepad. It works with Windows 7 and newer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.