Add menu item to Windows context menu only for specific filetype - windows-xp

I've developed 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.
How can I do that? Which registry keys should I use?

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.
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.
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.
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:
Create registry entry to associate file extension with application in C++

There's another key on the registry that works independently of user's default programs: HKEY_CLASSES_ROOT\SystemFileAssociations. Since nobody mentioned it on this question... No need to check ProgID before adding the context menu item. Example:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\.mkv\shell\subtitle]
#="Search subtitles..."
[HKEY_CLASSES_ROOT\SystemFileAssociations\.mkv\shell\subtitle\command]
#="\"D:\\Tools\\subsearch.exe\" \"%1\""
Reference: https://learn.microsoft.com/en-us/windows/desktop/shell/app-registration#registering-verbs-and-other-file-association-information
Additional Considerations:
The HKEY_CLASSES_ROOT subtree can be written to but in general is a view formed by merging
HKEY_CURRENT_USER\Software\Classes
file type registration visible to the current user only
HKEY_LOCAL_MACHINE\Software\Classes
globally register a file type on a particular computer
You can register to those classes instead/aswell
The (ProgID) defined verbs have priority over the same ones defined in ...\SystemFileAssociations\ , but are dependent on that particular Application, When that application uninstalls, it would normally delete its registry entry, along with what modifications/additions you may have done under that key. Or if the default (ProgID) is changed, your modifications will no longer be in effect.
The ...\SystemFileAssociations\ registrations are stable even when users change/uninstall the default programs.

Will publish my working solution derived from the previous answer (and one of its author's other answer).
It also adds an icon. I used it for all file types and didn't have administrator's privileges. The subitem * didn't exist in my registry, I created it myself.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\*]
[HKEY_CURRENT_USER\Software\Classes\*\shell]
[HKEY_CURRENT_USER\Software\Classes\*\shell\open_with_notepad_pp]
#="Open with Notepad++"
"icon"="C:\\portable\\npp.7.9\\notepad++.exe"
[HKEY_CURRENT_USER\Software\Classes\*\shell\open_with_notepad_pp\command]
#="\"C:\\portable\\npp.7.9\\notepad++.exe\" \"%1\""
UPDATE
Replace * with something like .svg and only for this extension the menu item will be shown.

Related

Word VSTO Get the default save location set by Office URI scheme

I am creating a new Word document from a template using the Office URI scheme with the nft command using the 'Optional Command argument 2' to set the default save folder.
Is it possible to retrieve the value of this default save folder from VSTO?
I have searched properties of the FileSaveAsDialog, properties of the ActiveDocument, properties of the Application, the CustomXmlParts in the document, and even investigated some WordBasic.FileNameInfo properties to see if it could be found there, but so far without success.
Take a look at the Options.DefaultFilePath property which returns or sets default folders for items such as documents, templates, and graphics.

Eclipse 4 RCP: What is the difference between Handled ToolItem/Direct ToolItem/Toolcontrol?

When adding a new item to a toolbar, you are given the option to choose Handled ToolItem, Direct ToolItem and Toolcontrol:
What is the difference between these three choices? I can't find the documentation for these anywhere.
'Handled' items are used when you have defined a command id and one or more handlers for the command. In the HandledToolItem you specify the id of the command that is to be executed.
'Direct' items are used when you just want to specify a Java class to be executed without using a command id and separate handler.
Toolcontrol is used when you want to write you own code for the control in the tool bar (something like a Combo for example).

Bug in the SSIS BIDS File System Task Editor?

Add a parameter to your package. Scope is not important. Set the Sensitive property to True.
Add a new File System Task to your package.
Double click to open the editor.
Set IsDestinationPathVariable = True
Attempt to set the property DestinationVariable.
You will see that the dialog box closes (crashes?) and you can never enter the variable.
It works fine for the SourceVariable property.
Yeah, this does look like a bug. However, I've found that if you open the Properties box for the File System Task, you can manually type in the variable name in the Destination property in the form User::VARNAME. Not an ideal workaround, but better than having to remove sensitive parameters during development.

Seperate error messages for required TextFields and DropDownChoices

I'm currently working on a Wicket 6.20 project which already has dozens of pages with TextFields and DropDownChoices. Now the requirement came up to change the default '${label}' is required. message to something more specific, depending on whether a TextField or a DropDownChoice doesn't have a value.
I know I can put Required=My Text in a properties file of the application, but that changes the message for all FormComponents. And specifying the full component path to either the TextFields or the DropDownChoices in the form of myform.mycontainer.mydropdownchoice.Required=My Text isn't feasible, since of course the structure of the Forms can differ on each page.
Ideally I'd like to put something like
org.apache.wicket.markup.html.form.DropDownChoice.Required=Please select a value for '${label}'
org.apache.wicket.markup.html.form.TextField.Required=Please enter a value in '${label}'
in my application's property file, either with or without FQCN.
Is there a way to achieve this with any of the default IStringResourceLoader that come with Wicket?
It is not necessary to provide the complete path to the components. It could be a path with just few parents:
mycontainer.mydropdownchoice.Required=My Text
mydropdownchoice.Required=My Text
If this still is not an option then you can override org.apache.wicket.markup.html.form.FormComponent#reportRequiredError() for any instance or type (e.g. MyDropDownChoice).

Updating XCode project template details

Previously all file headers were being displayed as follows.
// Created by ABC_User_Name on 10/31/11.
I have modified user name from ABC_User_Name to XYZ_User_Name.
Now, even after logging out & logging in again, I am finding the same headers in all project templates. How to update those templates with current user-name ?
Do I need to modify manually all of them ?
The original templates use this header:
// Created by ___FULLUSERNAME___.
// Copyright ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
The words with the double underscore are placeholder references. There are 18 that I know of, and you can add more in your template definition. These options can be further modified using option variables. The ones you see above are:
___FULLUSERNAME___ Full user name of the current user (name + surname).
__YEAR__ Current year.
___ORGANIZATIONNAME___ The name of your organization as seen on your address book. You can change it for each project selecting the Project node and setting the Organization field.
Once the project is created, the header becomes plain text and is never updated.
For future projects I suggest you duplicate the templates and do the changes there. Otherwise you risk screwing up the original templates or having Xcode overwrite your changes.
The originals are at:
/Developer/Library/Xcode/Templates/
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates
And I made a copy at:
mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Jano
mkdir -p ~/Library/Developer/Xcode/Templates/Project\ Templates/Jano
where "Jano" is my user and it will show as a template category in the new project selection screen.
Then you edit the header manually file by file, or from bash using sed.
Xcode 4 stores this on a per-project basis.
If you select the project in the Project Navigator (Cmd-1) and open the File Inspector (Cmd-Opt-1), you'll see a field for "Organization" under "Project Document".