仅针对特定文件类型将菜单项添加到Windows上下文菜单 [英] Add menu item to windows context menu only for specific filetype

查看:91
本文介绍了仅针对特定文件类型将菜单项添加到Windows上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序,该应用程序使用窗口的上下文菜单加载文件(右键单击文件),并且目前正在运行,但是reg键处于打开状态。

  HKEY_CLASSES_ROOT\ * 

并与所有文件。



我希望上下文菜单上的菜单项仅与.jpg文件一起显示。



<我该怎么办?我应该使用哪个注册表项?



谢谢。

解决方案

1)确定.jpg文件的文件类型(ProgID)



这可以通过检查默认值<$ c $来完成。 c> HKEY_CLASSES_ROOT\.jpg 。可能是基于您所安装内容的任何内容,但出于本示例的目的,我们将其称为 jpegfile ,这是常见的默认设置。



2)设置该文件类型的上下文菜单项(动词)属性



您可以设置 HKEY_CURRENT_USER\软件\类\jpegfile\shell 中的用户上下文菜单项。该键具有用于文件类型的动词列表。 HKEY_LOCAL_MACHINE\Software\Classes\jpegfile\shell 中有一个类似的键,这些是文件类型的系统默认值。您也可以在其中放置动词键,但是如果HKCU中存在相同的键,则会覆盖该键,因此建议您这样做。



3)设置命令值



命令的默认值是要使其正常工作而需要设置的最低最低键值子项。您需要使用应用程序的路径进行设置,如下所示: HKEY_CURRENT_USER\Software\Classes\jpegfile\shell\open_with_myapp\command c:\path\to\myapp.exe%1 。现在,.jpg文件的上下文菜单将具有一个 open_with_myapp项,该项将在单击时启动您的应用程序,并将所选文件的文件名作为参数传递。当然,您的应用程序如何处理参数取决于您,因此您需要将参数字符串设置为您的应用程序可以处理的东西。



4)设置其他动词属性



我想您可能希望上下文菜单项读取比键名更友好的内容。您可以通过设置该键的默认值( open_with_myapp )使上下文菜单显示您想要的商品标签。



这是您的基本概述。一定要检查一下我对这个有关关联文件的问题的答案,该答案具有类似的答案:




i've dveloped an application that load an image using the context menu of window (right click on the file) and for the moment is working, but the reg key is on

HKEY_CLASSES_ROOT\*

and it works with all files.

I want that the menu item on the context menu should be displayed only with .jpg files.

Whow i can do that? Which registry keys i should use?

Thanks in advance.

解决方案

1) Identify the file type (ProgID) for .jpg files

This can be done by checking the default value of HKEY_CLASSES_ROOT\.jpg. It could be anything based on what you've installed, but for the purposes of this example, we'll call it jpegfile, a common default.

2) Set the context menu item (verb) properties for that file type

You can set per-user context menu items in HKEY_CURRENT_USER\Software\Classes\jpegfile\shell. This key has a list of verbs for the file type. There is a similar key in HKEY_LOCAL_MACHINE\Software\Classes\jpegfile\shell, and these are the system defaults for the file type. You can put a verb key there too, but if the same key exists in HKCU, it will be overridden, so be advised.

3) Set the command value

The bare minimum key value that needs to be set to get it to work is the default value of the command subkey. You need to set that with the path to your application, like so: HKEY_CURRENT_USER\Software\Classes\jpegfile\shell\open_with_myapp\command would be set to "c:\path\to\myapp.exe" "%1". Now a context menu for .jpg files will have a "open_with_myapp" item which will launch your app when clicked, and pass the file name of the selected file as a parameter. Of course, how your application processes parameters is up to you, so you'd need to set the parameter string to something your app can process.

4) Set other verb properties

I'd imagine you're probably going to want the context menu item to read something a little more friendly than the key name. You can have the context menu display whatever label you want for your item by setting the default value of that key (open_with_myapp).

That's your basic overview. Definitely check out my answer to this question about associating a file, which has a similar answer:

这篇关于仅针对特定文件类型将菜单项添加到Windows上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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