Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

registry - Add menu item to windows context menu only for specific filetype

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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_USERSoftwareClassesjpegfileshell. This key has a list of verbs for the file type. There is a similar key in HKEY_LOCAL_MACHINESoftwareClassesjpegfileshell, 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_USERSoftwareClassesjpegfileshellopen_with_myappcommand would be set to "c:pathomyapp.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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...