Programming for the Shell

Suppose that every time you copied a bitmap file, its image was made available on the clipboard. Currently, Windows does not support this functionality. But with a data handler (see Chapter 8) you could easily add this feature yourself. Maybe you would like to navigate into an Access database as if it were just another directory in the filesystem. You could do it with the proper namespace extension (see Chapter 12). Or you might like to automatically process information on a web page (say, your online brokerage account) every time you navigated to the URL. A browser helper object is the answer (see Chapter 13).

These are just a few examples of the many things you can accomplish by programming the shell. But all of these examples, and all shell components in general, share one common attribute: they integrate fully with Explorer. This gives the impression that they are actually a part of the shell itself, and technically, they are. Why is this important? Chances are, the application that is used the most by Windows users world-wide is Explorer.exe. It is probably familiar to more people than any other application. This means that, by integrating your application with the shell, you automatically make at least a portion of your application’s functionality conveniently and easily available to anyone who is accustomed to working with the shell. An excellent example is the popular WinZip program developed by Niko Mak Computing, Inc: the two most common processes of archive management—adding and extracting files from a .zip file—can be accomplished from the shell without directly opening the WinZip program itself.

This shell integration in turn offers a number of advantages:

Greater ease of use

Because users of your application can work with an interface that’s consistent with that of Windows as a whole, they will find your application easier to learn and use. As a result, users will be happy with, rather than frustrated by, your application.

A more professional application

How many times have you used a “Windows” application that just didn’t seem to be written for Windows? Perhaps it had its own printer drivers. Maybe it deleted files outright rather than moving them to the Recycle Bin. Or possibly its windows just looked funny. In any case, applications that fall into this category for whatever reason are typically perceived as inelegant and amateurish. By integrating your application with the shell, there are fewer surprises for the user, and your application succeeds in conveying your professionalism as a programmer.

Greater programming expertise

As we’ll see shortly, the Windows shell is one central area of Windows programming that is very poorly documented. Shell programming also relies heavily on COM, which is cloaked in obscurity for many VB (and even C++) programmers. Hence, when you’re programming the Windows shell, you’re working on the cutting edge in two areas. For those to whom programming is a passion as well as a profession, shell programming—and the knowledge gained from it—is extremely rewarding.

Clearly there are advantages to developing shell extensions and integrating your applications with Windows Explorer. There are also challenges. Traditionally, developing shell extensions has been seen as a topic for experienced C and C++ programmers only; very few programmers are aware that you can create shell extensions using Visual Basic.

In addition to the fact that few programmers know that VB can be used to create shell extensions, the state of the documentation on programming the Windows shell is perhaps worse than in any other area. Possibly Microsoft felt that, despite the centrality of the Windows shell in the Windows operating system, programming the shell was too complex and too specialized for most programmers. Hence, even for C/C++ programmers, figuring out how to create a particular kind of shell extension and getting it to work is no easy matter.

But we’ll surmount the first of these obstacles—the mistaken belief that VB cannot be used for shell programming—by showing you how to develop shell extensions. We’ll also help you to surmount the second obstacle by providing the basic documentation on the shell and its COM interfaces that you can use when building your own shell extensions.

Get VB Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.