[ SourceForge.net | Project | izfree | Tutorials | Tutorial 4 ]

Tutorial 4: Adding Shell Verbs

Zoom is a flexible image resizing program with lots of command line arguments. Remembering all those arguments and their exact meaning can be difficult. Common image resizing tasks are to double the size of an image, or resize it to fit dimensions of a 1280x1024 desktop. We can extend the Windows Shell to provide new resize verbs for the kinds of image files that zoom understands. The following commands implement the verbs for common resizing operations.

Zoom 2x "C:\Program Files\Zoom\zoom.exe" -filt mitchell -square -src "%1" -dst "%1-2x.jpg" -d 0 0 6000 6000 -map 2 2 0 0
Zoom 1280x1024 "C:\Program Files\Zoom\zoom.exe" -filt mitchell -square -src "%1" -dst "%1-1280x1024.jpg" -d 0 0 1280 1024
Zoom 1280 "C:\Program Files\Zoom\zoom.exe" -filt mitchell -square -src "%1" -dst "%1-1280.jpg" -d 0 0 1280 6000
Zoom 1024 "C:\Program Files\Zoom\zoom.exe" -filt mitchell -square -src "%1" -dst "%1-1280.jpg" -d 0 0 6000 1024
Zoom Blur "C:\Program Files\Zoom\zoom.exe" -filt mitchell -square -src "%1" -dst "%1-blur.jpg" -blur 2

You can enter this information manually after you install zoom, assuming you installed it to C:\Program Files\Zoom, through the Folder Options / File Types dialog in the shell. The quotation marks are necessary to quote the spaces in the paths of the files for proper argument parsing with the shell.

If you run REGEDIT after adding the verbs with the folder options dialog you can see that this information was entered into some registry keys under HKCR\jpegfile. You might have been expecting to see the information stored under HKCR\.jpg, but Windows uses an extra level of indirection between the file extension and its file association type. In our case, this allows a single verb to work on JPEG files stored with extensions .JPG, .JPE, or .JPEG, which are all mapped to the file asocation type jpegfile.

Great, except there's one problem. The user can install zoom.exe anywhere on the machine, not just C:\Program Files\Zoom, and may not have that location in their path. So we can't depend on the above commands to work if used literally as they appear above. What we need to do is format the commands when the installation is run so that the location of zoom.exe will be resolved to the proper location for that target machine.

With the Formatted string type in Windows Installer, you can obtain the installed location of any file by using the syntax [#File key], where File key is the primary key of a row in the File table.

In our case, we want the location of the zoom.exe, which had a generated file key of f0_zoom.exe. Substituting [#f0_zoom.exe] for C:\Program Files\Zoom\zoom.exe in the above commands localizes them properly on the target machine. For example:

"[#f0_zoom.exe]" -filt mitchell -square -src "%1" -dst "%1-2x.jpg" -d 0 0 6000 6000 -map 2 2 0 0

Note that the quotes (") are still part of the command. The location of zoom still needs to be quoted for the shell, in case it was installed into a directory containing spaces, such as Program Files.

Now we just need to write those strings into the registry, which we do with the Registry table. You might think that we want to use the Verb and Extension tables for this, but in this case we don't. Zoom isn't acting as the COM server for the JPEG file type, it is only adding some command-line shorthands to the shell's context menu for JPEG files.

  1. Open the installation database and display the Registry table.

  2. Add the following new rows for the shell commands and verbs listed above. The data for the Value column of each row is the appropriate shell command listed above.

    Registry Root Key Name Component_
    rvJPEGDouble 0 jpegfile\shell\Zoom 2x\command NULL Executable
    rvJPEG1280x1024 0 jpegfile\shell\Zoom 1280x1024\command NULL Executable
    rvJPEG1280 0 jpegfile\shell\Zoom 1280\command NULL Executable
    rvJPEG1024 0 jpegfile\shell\Zoom 1024\command NULL Executable
    rvJPEGBlur 0 jpegfile\shell\Zoom Blur\command NULL Executable

  3. Validate the database to check for any errors made during editing and save your changes.

Now when you install Zoom, the context menu (and File menu, in Windows Folder views) will display the items "Zoom 2x", "Zoom 1280x1024", "Zoom 1280", "Zoom 1024", and "Zoom Blur". Selecting one of these will perform the operation on the selected file and produce a new file containing the result in the same directory. The output files are created from the input filenames with a suffix added.

You can add verbs to use zoom as an image conversion program, although this is not its primary purpose, by giving the source and destination filenames different extensions, such as zoom -src "%1" -dst "%1.jpg" will convert a file to JPEG format. You can also add verbs for the other file types supported by zoom. zoom -dev ? provides a list of understood formats.