简体   繁体   English

如何使用C#将具有子项的项添加到系统上下文菜单

[英]How to add items with subitems to system context menu using C#

I want to add some new items (with subitems) of my software to context menu like this 我想将我的软件的一些新项目(带有子项目)添加到这样的上下文菜单中

So I looked in the registry and found this: 所以我查看了注册表,发现了这个:

And I guess that the software "Google Drive" had created some owner classes (or service) to add command to its context menu, and the string {BB02B294-8425-42E5-983F-41A1FA970CD6} is the presentation of this service (or classes), like the Windows SendTo Service (Right click -> Send To) 我想软件“Google Drive”已创建了一些所有者类(或服务)来向其上下文菜单添加命令,字符串{BB02B294-8425-42E5-983F-41A1FA970CD6}是此服务(或类)的表示),像Windows SendTo服务(右键单击 - >发送到)

But how to do that? 但是怎么做呢?

First of all the most important thing, there is no way to create nested context menus without context menu handlers .A context menu handler is nothing but a registered COM Server on the users computer.A COM Server exists in the form of a dynamic link library.To explain it better,let me take an example from your first image;The menu entry named Google Drive is a COM Server and entries Copy to Folder and Move to Folder are simple shortcut entries in the registry.Making shortcut entries with specific commands is relatively easy. 首先,最重要的是, 没有上下文菜单处理程序就无法创建嵌套的上下文菜单 。上下文菜单处理程序只是用户计算机上注册的COM服务器 。一个COM服务器以动态链接库的形式存在为了更好地解释一下,让我举一个第一张图片的例子;名为Google Drive的菜单条目是一个COM服务器,条目复制到文件夹移动到文件夹是注册表中的简单快捷方式条目。使用特定命令创建快捷方式条目是相对容易。
To make a shortcut at the desktop context menu for example to Launch Notepad ,locate the following registry key in registry editor, [HKEY_CLASSES_ROOT\\Directory\\Background\\shell] ,create a new key in it,name it Launch Notepad ,in its default value add this, Execute Notepad .Now create a new key under Launch Notepad and name it command and add this to its default value notepad.exe .That's it,now right click on your desktop you will notice a new entry named Execute Notepad ,clicking it will open Notepad.So that was the method to create a simple shortcut entry,please note that these shortcut entries cannot be nested means you cannot add any entry under Execute Notepad entry. 要在桌面上下文菜单中创建快捷方式,例如启动记事本 ,请在注册表编辑器中找到以下注册表项, [HKEY_CLASSES_ROOT \\ Directory \\ Background \\ shell] ,在其中创建一个新密钥,将其命名为Launch Notepad ,默认值为添加这个, 执行记事本 。现在在启动记事本下创建一个新密钥,并命名为命令 ,并将其添加到其默认值notepad.exe 。就是这样,现在右键单击您的桌面,您会注意到一个名为Execute Notepad的新条目,单击它将打开Notepad。因为这是创建简单快捷方式条目的方法,请注意这些快捷方式条目不能嵌套意味着您无法在Execute Notepad条目下添加任何条目。

Now if you want to learn how to get started in making shell extensions,have a look here . 现在,如果您想学习如何开始进行shell扩展,请查看此处
Hope this would have helped you. 希望这会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM