简体   繁体   中英

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).

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

and

<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 ie for MS Access I use :

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.

Of course, always back up your registry before hacking it.

Your program could do this during install, or on first run.

您还可以将Java程序打包在NSIS之类的安装程序中,并且可以使用NSIS脚本生成资源管理器上下文菜单

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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