简体   繁体   English

如何为Java应用程序向Windows资源管理器添加上下文菜单?

[英]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.

相关问题 如何仅在项目中的.java文件中在项目资源管理器上下文菜单中添加弹出菜单 - How can I add popup menu in Project explorer context menu, only for .java files in project java中的Windows资源管理器上下文菜单 - windows explorer context menu in java 如何使用 java swing 中的 windows 资源管理器上下文菜单打开.txt? - How to open .txt using windows explorer context menu in java swing? 如何将上下文菜单项添加到Windows资源管理器中用于exe以外的文件夹 - How add context menu item to Windows Explorer for folders different than exe 从 Windows 上下文菜单运行 Java 应用程序 - Running a Java Application from the Windows Context Menu 如何在Java应用程序中使用系统的上下文菜单? - How can I use the system's context menu for files in a Java application? 如何将不同的菜单项添加到多个上下文菜单? - How can I add different menu items to multiple context menus? 如何将上下文菜单添加到表格布局? - How can I add a Context Menu to a Table Layout? 如何将不同的菜单项添加到多个上下文菜单? - How can I add different menu items to multiple context menus? 将Windows资源管理器上下文菜单(右键菜单)的FilePath获取到Java - Get FilePath of Windows Explorer Context Menu (Right-click menu) to Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM