3

I've found a very nice tutorial and i am trying to understand something that is not in this tutorial (because the tut itself works fine) http://www.codeproject.com/Articles/9163/File-Rating-a-practical-example-of-shell-extension

When you look at applications like WinRar, TortoiseSVN, Antivirus-apps and many more, there is an icon next to the Shell Extension Item.

I would like to know how this is done. (Programmatically with C#)

Adding a separator works, adding a submenu works and click+action also works, but i'm struggling with the icon. This cannot be so hard. Can somebody help me?

And please don't say that Microsoft doesn't longer support this in .NET 4.0, because it is not guaranteed and therefore they don't supply samplecode. If all those other apps can do it, then it is possible.

Please supply me some sample code, some tutorials or maybe even a working piece of code.

4

3 回答 3

3

请看下面的文章,它使用 .NET 4.0 它使用SharpShell nuget 包创建 Windows Shell 扩展。

NET Shell 扩展 - Shell 上下文菜单

使用此库,您可以在创建上下文菜单条时直接设置图像,如下所示

protected override ContextMenuStrip CreateMenu()
{
    //  Create the menu strip.
    var menu = new ContextMenuStrip();

    //  Create a 'count lines' item.
    var itemCountLines = new ToolStripMenuItem
    {
        Text = "Count Lines...",
        Image = Properties.Resources.CountLines
    };

    //  When we click, we'll count the lines.
    itemCountLines.Click += (sender, args) => CountLines();

    //  Add the item to the context menu.
    menu.Items.Add(itemCountLines);

    //  Return the menu.
    return menu;
}
于 2013-04-24T13:37:46.777 回答
2

您只需添加到以下注册表项:HKEY_LOCAL_MACHINE\SOFTWARE\Classes*\shellex\ContextMenuHandlers,这是代码:

 string TimeStamp = DateTime.Now.ToString("dd-MM-yyyy");

string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\*\\shellex\\ContextMenuHandlers\\Winrar";
string valueName = "MyWinrar";
Microsoft.Win32.Registry.SetValue(key, valueName, HERE WHAT YOU WANT TO START, Microsoft.Win32.RegistryValueKind.String);

我希望这个对你有用!

于 2014-01-21T18:59:42.060 回答
0

您列出的所有应用程序都使用 COM 和非托管代码来创建覆盖图标处理程序。甚至还有一个特殊的项目 TortoiseOverlays,它提供了一个通用库,用于为 TortoiceCSV、TortoiseSVN 和 TortoiseGIT 绘制图标。您可以查看它的源代码以了解它是如何完成的。如果您想绘制类似的图标,您可能应该重复使用它。

不建议将 .Net 用于此类扩展,因为当针对不同 .Net 版本构建的多个扩展会尝试在资源管理器进程中加载​​时,它们会使资源管理器崩溃。

于 2013-04-24T13:32:26.140 回答