如何为Java应用程序的Windows资源管理器添加上下文菜单? [英] How can I add a context menu to the Windows Explorer for a Java application?

查看:109
本文介绍了如何为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?

推荐答案

我知道有两种方法可以做到。花哨的方式是编写一个windows shell扩展,这就是powerarchiver,winzip等我认为这样做(这涉及运行代码来确定上下文菜单项将取决于所选择的文件)。

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 :

HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command

其中<文件类型> 是此上下文菜单应适用的文件,即*,。mdb,.doc

Where <file type> is the files that this context menu should apply to i.e. *, .mdb, .doc

< display text> 您要在上下文菜单中显示的内容。

<display text> what you want to show in the context menu.

然后从上下文菜单中添加默认字符串作为要启动的应用程序的路径,并且可以使用%1来引用当前选定的文件,即我使用的MS Access :

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 :

HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"

然后为我选择的任何文件(因此*)添加一个上下文菜单项,这允许我在MS Access 2000中启动它。

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应用程序的Windows资源管理器添加上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆