如何向 Java 应用程序的 Windows 资源管理器添加上下文菜单?
如何为 Java 应用程序添加一个子菜单项到 Windows 资源管理器上下文菜单(例如 7-Zip 就是这样做的)?
How would one go about adding a submenu item to the windows explorer context menu (like for example 7-Zip does) for a Java application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道有两种方法可以做到这一点。 最奇特的方法是编写一个 Windows shell 扩展,我相信 powerarchiver、winzip 等就是这样做的(这涉及运行代码来确定上下文菜单项将依赖于所选文件)。
对于简单的功能,简单的方法是您可以在注册表中添加一个条目:
其中
是此上下文菜单应适用的文件,即 *、.mdb、.doc和
您想要在上下文菜单中显示的内容。然后将默认字符串添加为要从上下文菜单启动的应用程序的路径,并且您可以使用 %1 来引用当前选定的文件,即我使用的 MS Access:
然后为任何文件添加一个上下文菜单项我选择(因此是 *),这允许我在 MS Access 2000 中启动它。
当然,在破解注册表之前一定要备份它。
您的程序可以在安装期间或首次运行时执行此操作。
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).
The simple way, for simple functionality, is you can add an entry in the registry :
Where
<file type>
is the files that this context menu should apply to i.e. *, .mdb, .docand
<display text>
what you want to show in the context menu.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 i.e. for MS Access I use :
This then adds a context menu item for any file I select (hence the *), which allows me to launch it in 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 脚本生成资源管理器上下文菜单
You could also package the java program in an installer like NSIS and you could use NSIS script to generate explorer context menu