- Add Any Folder to the Start Menu
- Folder Pointers: Download It Here
A shell namespace extension needs to implement an IShellView interface to display the contents of a virtual folder in Explorer. But, as I explained earlier, folder pointers are designed to work only when the Start menu is visible. That means that the contents can't be accessed through an Explorer window, because the Start menu isn't visible at the moment of enumeration. So instead of using the IShellView interface to display the folder contents, I used it to display a dialog with information about the program.
Folder Pointers also extends the behavior of the shell by implementing the shell extension interfaces IContextMenu and ICopyHook. An IContextMenu shell extension interface lets you add items to the context menu of a particular file type. ICopyHook is a COM-based interface that is called by the shell every time a folder is about to be moved, copied, renamed, or deleted, and it gives you the chance to allow or deny the operation.
I added an IContextMenu shell extension to display the Folder Pointer menu when you right-click a folder or a folder pointer inside the Start menu. Windows only lets you set IContextMenu shell extensions for an entire file type, so to add it to the Start menu I had to add it to every file system folder. I did this by registering it under the key HKEY_LOCAL_MACHINE\Folder\ shellex\ContextMenuHandlers. But I only want to add the Folder Pointer menu to folders located inside the Start menu. This can be handled at run time.
Each time the system is about to pop up the context menu, it calls any context menu handlers defined for that file type. The context menu handler can add one or more items to the context menu, but it doesn't have to. So my context menu handler analyzes the passed filename, and only adds the Folder Pointers submenu to folders on the Start menu.
When the shell initializes the IContextMenu extension, it first calls IShellExtInit::Initialize(), passing it a pointer to an IDataObject interface that can be used to retrieve the name of the folder being clicked. After the proper format conversions, the retrieved folder name is used in a call to the program function InStartMenu(). This function returns TRUE if the folder in question resides inside a Start menu. If the folder isn't located inside a Start menu, the IShellExtInit::Initialize() function returns E_NOTIMPL and the shell does not call QueryContextMenu() to add the menu items. The IShellExtInit::Initialize() method also checks if the folder being clicked is a folder pointer. If it is, it sets the BOOL variable IsFPointer to TRUE. This variable is used by QueryContextMenu() to determine whether it should enable the New folder pointer command on the Folder Pointers menu. If it is a folder pointer, then the New folder pointer option is not enabled.
The ICopyHook shell extension is used to prevent the user from copying or moving Folder Pointers out of the Start menu. This is necessary because folder pointers were designed to work only from the Start menu, and because the Uninstall() function only looks inside the Start menu for folder pointers to remove.
The ICopyHook extension differs from other shell extensions in that it is called directly by the shell without first calling any initialize method. It has to be registered under the registry key HKEY_CLASSES_ROOT\Directory\shellex\CopyHookHandlers to be recognized by the system. Note that the ICopyHook extension does not protect against every possible way of creating a folder pointer outside of the Start menu. The user can still create one manually.
The ICopyHook implementation only contains one method: CopyCallBack(). The names of the source folder and the destination folder are passed to the ICopyHook::CopyCallBack() method. The extension uses these parameters to determine whether the source folder is a folder pointer and the destination folder is outside of the Start menu. If so, it displays a message to the user saying that folder pointers can't exist outside of the Start menu, and returns IDNO to indicate to the shell that the operation should be canceled.