1.3 Kinds of Shell Extensions

only for RuBoard - do not distribute or recompile

1.3 Kinds of Shell Extensions

Since our topic is the combination of shell programming and COM, we'll focus on building the following shell extensions, all of which rely on COM interfaces to be loaded and invoked by the shell:

Context menu handlers

A context menu is the pop-up menu that appears when you right-click on an object in Explorer. A context menu handler allows you to customize that menu by adding your own items to it. For instance, if you develop an application that stores thumbnails of graphics files, you might add an "Add to Thumbnail" option to the context menu of any supported graphics file. When the user selects the file, it is automatically added to the application's current thumbnail.

Drag-and-drop handlers

These are specialized context menu handlers; they control the pop-up menu that appears when a shell object is dragged and dropped using the right mouse button.

Icon handlers

Ordinarily, each file type has its own icon. For instance, every Word document is represented by a single icon that serves to identify it. An icon handler, though, allows you to define an icon for an individual instance of that file based on some attribute or condition of the file (its contents, its size , the date it was created, etc.). A classic example is the icon for the Recycle Bin: when it is empty, the Recycle Bin is represented by an empty trash can; when it is not empty, the Recycle Bin is represented by an overflowing trash can.

Property page extension

Every shell object has a Properties dialog that displays one or more property pages when the user selects the Properties menu option for that object. Like many of the features of the shell, the Properties dialog is extensible: you can write property page extensions that add pages to the dialog. An excellent example of thisand itself a powerful feature that can give the user greater control over his documentsis the Custom tab of a Word document's Properties dialog, which allows the user to define custom properties and modify their values.

Drop handler

Drop handlers allow your files to become drop targets. Once again, WinZip provides a good example. Consider what occurs when you drop a file (or files) onto a file object of type .zip : after you drop the files, a dialog is displayed that gives you the opportunity to add the files to the .zip file. This functionality is achieved through a drop handler.

Data handler

A data handler provides additional clipboard formats for a file object. In layman's terms, this means you can define additional behaviors for a file object during a cut-and-paste operation. There is almost no limit to what you can do with a data handler. When you copy your quarterly financial report (a spreadsheet in Excel), your data handler could place it in the clipboard as a graph. The graph would then be available from any program (via the Paste command) that knows how to deal with bitmaps, such as Microsoft Paint, Adobe Photoshop, Paint Shop Pro, etc.

Copy hook handler

Copy hook handlers are called by the shell before a move, delete, rename, or copy operation. The handler merely approves or disapproves the action. This handler might keep you from accidentally deleting your source code library!

InfoTip handler

InfoTip handlers are a nice touch for any file object. Microsoft Word documents provide a good example. Hold your cursor over any .doc file. After a brief moment, a tooltip (or InfoTip) listing the author of the document is displayed.

Namespace extension

My Computer, the Recycle Bin, and Network Neighborhood (to name a few) are all namespace extensions. Namespace extensions allow you to display your hierarchical data as if it were just another folder in the system. Imagine being to able to navigate into an Access database file right from Explorer. Namespace extensions also allow the creation of custom system folders, like the Fonts directory that is found in the Windows folder. This folder contains only fonts and provides additional user interface elements that are specific to fonts, like Print Preview.

Browser helper objects

Browser helper objects, or BHOs, give you access to every running instance of Internet Explorer. Through the Microsoft DHTML object model, a browser helper object also has access to every element of the web page that is currently being displayed. Maybe you would like to automatically convert every web page you view into Spanish. Maybe you need to restrict your customers' browsers to the corporate Intranet. You can do just about anything Internet- related with a browser helper object.

Browser extension

Browser extensions have all the same functionality as browser helper objects, but with two exceptions: they allow you to trigger their functionality via a menu item or toolbar button. For instance, you might write a browser extension that allows you to highlight a company's ticker symbol on any web page. When you press the toolbar button for the extension, the extension could get a real-time stock quote for the symbol and display it in a pop-up. Like browser helper objects, the only limit is your imagination .

Band objects

The Search, History, and Favorites windows that are a part of Internet Explorer are actually band objects. Remember the ill-fated Channel window in Windows 98? That was a band object, too. If you have an Internet-related application that needs a user interface, a band object is the way to go.

Docking Windows

Docking windows are toolbars that can be added to Explorer's client area. They are a great way to provide your other shell components with an additional user interface.

Not every aspect of the Windows shell has something to do with COM. Say, for instance, you want to add your program icon to the system tray. You really only need a few API calls that have nothing to do with COM in order to achieve this. Therefore, I won't discuss tray icons in this book. While this book does deal extensively with the shell, the main purpose of this book is to describe the mechanisms by which we can extend the functionality of the Windows operating system by using COM. System tray icons are pretty cool, but they don't really extend the operating system in any way. This is primarily a book on the shell. The secondary focus of the book is writing components with COM.

only for RuBoard - do not distribute or recompile