Definitions

Before you begin looking at the samples, it will be useful to define some terms. You've seen many of the terms before, but these definitions emphasize how the terms are used in the context of this chapter.

Let's start with folders. A folder is simply a collection of objects in the shell name space. Although it is much like a file system directory, a folder can also be a container for remote computers, storage devices, the desktop, Control Panel, and so on. A folder can contain other folders as well as file objects, but each type of folder contains only certain types of file objects—for example, you cannot drag a Control Panel application into a file system directory folder. A file object is an object in a folder, such as an actual file, a printer, or some other type of object.

An item identifier (item ID) is a binary data structure that uniquely identifies an object in the object's parent folder. When you need to trace a path to an item from the desktop, you use an item ID list. The user never sees item IDs; display names are shown instead. A PIDL (pronounced “piddle”—stop giggling) is a pointer to an ID list, used with many of the functions that let you browse the shell name space.

Each folder is an OLE object that knows how to enumerate its contents and carry out other actions. To do this, folders implement the IShellFolder interface. When an application gets a pointer to the IShellFolder interface for a folder, this is referred to as binding to the folder. Your application can bind to the desktop folder by using the SHGetDesktopFolder function. Your application can also bind to a subfolder of any given folder by using the IShellFolder::BindToObject member function. With these two functions, an application can browse through the shell's entire name space, as you'll see later in the chapter.

Some folders are known as virtual folders. Virtual folders aren't actual file directories or storage devices. Rather, they are containers for a number of storage devices and network resources. Examples of virtual folders are the desktop folder, the My Computer folder, and the Network Neighborhood folder. Other virtual folders contain file objects, such as printers, that are not part of the file system.

File system directories also use some special folders. For example, the Programs folder contains the user's program groups, and the desktop directory physically stores files that have been copied to the desktop folder. You can find these special folders in the Registry under HKEY_CURRENT-_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders.

An application uses the SHGetSpecialFolderLocation function to retrieve the location of a special folder, whether it is a virtual folder or part of the file system. The function returns a PIDL, which the application must eventually free by using the task allocator. If the folder is part of the file system, you can convert the PIDL to a file system path by using the SHGetPathFromIDList function.