[英]How can I add a context menu to the Windows Explorer for a Java application?
如何为Java应用程序向Windows资源管理器上下文菜单中添加子菜单项(例如7-Zip)?
I am aware of two ways to do it. 我知道有两种方法可以做到这一点。 The fancy way is to write a windows shell extension, which is how powerarchiver, winzip etc do it I believe (this involves running code to determine what the context menu items will be dependent on the file chosen). 一种奇特的方法是编写一个Windows Shell扩展,这是我相信powerarchiver,winzip等如何执行的方式(这涉及运行代码以确定上下文菜单项将取决于所选文件)。
The simple way, for simple functionality, is you can add an entry in the registry : 对于简单的功能,简单的方法是可以在注册表中添加一个条目:
HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command
Where <file type>
is the files that this context menu should apply to ie *, .mdb, .doc 其中<file type>
是此上下文菜单应应用于的文件,即* 、. mdb,.doc
and 和
<display text>
what you want to show in the context menu. <display text>
您要在上下文菜单中显示的内容。
Then add the default string as a path to the application you want to launch from the context menu, and you can use %1 to refer to the currently selected file ie for MS Access I use : 然后将默认字符串添加为要从上下文菜单中启动的应用程序的路径,您可以使用%1来引用当前选择的文件,即对于我使用的MS Access:
HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"
This then adds a context menu item for any file I select (hence the *), which allows me to launch it in MS Access 2000. 然后,这为我选择的任何文件添加了一个上下文菜单项(因此带有*),这使我可以在MS Access 2000中启动它。
Of course, always back up your registry before hacking it. 当然,始终在黑客入侵之前备份您的注册表。
Your program could do this during install, or on first run. 您的程序可以在安装过程中或首次运行时执行此操作。
您还可以将Java程序打包在NSIS之类的安装程序中,并且可以使用NSIS脚本生成资源管理器上下文菜单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.