3.2 Shell Extensions

only for RuBoard - do not distribute or recompile

3.2 Shell Extensions

Every file object visible in the shell is a member of a file class and can be programmatically extended by a shell extension. There are certain predefined actions that determine which shell extensions will be invoked. These actions include things like right-clicking, copying, moving, dragging, cutting, pasting, and even displaying an icon for a file. Shell extension handlers are in-process COM servers that implement a variety of interfaces, depending on the type of handler being implemented. There are five handlers that perform actions based on a specific file type:

  • Context menu handlers

  • Icon handlers

  • Property sheet handlers

  • Drop handlers

  • Data handlers

There are also two types of handlers that are associated with file operations like copying, moving, renaming, and deleting:

  • Copy hook handlers

  • Drag-and-drop handlers

3.2.1 Context Menu Handler

A context menu is the menu that appears when a file is right-clicked. A sample context menu is shown in Figure 3.1. Every item in the shell has an associated context menu. This menu provides the means to perform generic operations such as copying, moving, deleting, and renaming file objects.

A context menu handler allows items to be added to this menu for a specific file object. This allows custom processing to be performed on the file object via the menu selection.

Figure 3.1. Context menus provide a means for additional file processing from within the shell
figs/vshl.0301.gif

Context menu items can be defined quite easily in the registry without writing any code whatsoever. But there are situations where you may need to display a different menu for file objects of the same type. This is where context menu handlers come into play. For example, you might want to add a Backup option to a context menu for a file whose archive bit is set. Or you might want to determine whether a file's size exceeds a floppy drive's free space before displaying a Copy to Floppy menu option.

3.2.2 Icon Handler

Every file object has an associated icon. Icons for a given file object are specified in the registry by a subkey called DefaultIcon under the object's application identifier key. You could, for example, change the icon the shell displays for your hard drives by changing the default value of the key shown in Figure 3.2. The number 8 in Figure 3.2 refers to the index of the icon that is contained in shell32.dll .

Figure 3.2. Default icon location
figs/vshl.0302.gif

Icon handlers provide a way to display different icons for the same file objects on a per instance basis. These icons can be used to provide additional state information for a file or resource. For instance, a .rad file (this is a made-up file type that we will use to discuss handlers) could display an icon representing the type of animal specified by the file, as Figure 3.3 shows.

Figure 3.3. Icon handlers provide per-instance icon support
figs/vshl.0303.gif

3.2.3 Property Sheet Handler

Property sheet handlers add pages to the property dialog for a specific file object. These additional property pages allow for additional file processing in much the same manner as a context menu handler. These pages can be specific to a class of file objects or to an individual file object, depending on the needed functionality. For example, Figure 3.4 shows the default property sheet for a text file.

Figure 3.4. Default property sheet
figs/vshl.0304.gif

The Microsoft Word .doc file Properties dialog provides a good example of property sheet handlers. The property sheet extension adds not one, but four pages in addition to the default property sheet, as illustrated in Figure 3.5. A wide variety of document attributes can then be changed right from the shell without the need to open Word.

Figure 3.5. .doc file property sheets
figs/vshl.0305.gif

3.2.4 Data Handler

Data handlers provide custom clipboard formats that are made available whenever a file object is dragged from the shell or copied to the clipboard. They can be used to alter the default copy-and-paste behavior implemented by the shell. Consider a .bmp file for a moment. Suppose that when you copied the file from the shell, you also wanted the image that the file represented to be made available from the clipboard. A custom .bmp data handler would allow you to copy image data right from the shell into another program such as Adobe Photoshop.

3.2.5 Drop Handler

A drop handler allows a file of a specific class to become a drop target. Consider one of the most popular shareware programs around, WinZip. WinZip defines a drop handler for files of type .zip . When files are dropped onto a .zip file, a drop handler processes the files and add them to the archive. Drop handlers allow you to define such behaviors for your own file types.

3.2.6 Copy Hook Handler

Copy hook handlers are associated with folder objects (they are valid for folder objects only and do not pertain to files) and are called before a folder is copied, moved, renamed , or deleted. They do not perform the task, but rather they approve or disapprove the task. Copy hook handlers could be used to keep your favorite source code directory from being accidentally deleted or moved.

3.2.7 Drag-and-Drop Handler

A drag-and-drop handler is nothing more than a context menu handler that is displayed when a file is dragged with the right mouse button. Since they are similar to context menus, drag-and-drop handlers are discussed in Chapter 4.

only for RuBoard - do not distribute or recompile


Visual Basic Shell Programming
Visual Basic Shell Programming
ISBN: B00007FY99
EAN: N/A
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net