Shell extensions for an operating system6008806Abstract An operating system provides extensions through which application developers may extend the capabilities of a shell of the operating system. For example, application developers may add menu items to context menus for objects that are visible within an integrated system name space. In addition, developers may add property sheet pages for such objects. Application developers also have the option of providing per-instance icons for each instance of an object. Application developers may provide data object extension handlers for customizing data sources on a per-object class basis and may provide drop target extension handlers on a per-object class basis to customize drop target behavior. Developers may additionally provide copy-hook handlers to regulate file system operations on objects. Developers may also extend the functionality provided by the shell of the operating system by adding their own custom name spaces to the integrated system name space. The mechanism provided by the operating system to add such a name space is polymorphic and transparent to users. Claims The embodiments of the invention in which an exclusive property or privilege is claimed are defined as follows: Description FIELD OF THE INVENTION
______________________________________
1: .doc = AWordProcessor
2: AWordProcessor = A Word Processor
3: shell = open print preview
4: open
5: command = c:\aword\aword.exe %1
6: print
7: command = c:\aword\aword.exe /p %1
8: printTo
9: command = c:\aword\aword.exe /pt %1%2%3
10: preview = Pre&view
11: command = c:\aword\aword.exe /r %1
12: shellex
13: ContextMenuHandlers = ExtraMenu
14: ExtraMenu = {00000000-1111-2222-3333-00000000000001}
15: PropertySheetHandlers = SummaryInfo
16: SummaryInfo = {00000000-1111-2222-3333-
00000000000002}
17: IconHandler = {00000000-1111-2222-3333-00000000000003}
18: DefaultIcon = %1
______________________________________
This example portion of the registry will be discussed in more detail below when focusing on the particular types of extensions. The preferred embodiment allows a developer to customize context menus for objects by specifying customized static verbs and dynamic verbs. A "verb" is a kind of action that is defined by an object and its associated server. In the context menus, a verb is an action that is performed in response to the selection of an associated menu item. For example, the menu item "Open" has an associated verb that opens the file or object. Verbs are supported by the "MICROSOFT" OLE 2.01 protocol. Static verbs are those verbs that are registered under the "shell" key (note line 3 in the above example) within the registry 28. Static verbs may be contrasted with dynamic verbs, which are discussed in more detail below. In the above example, static verbs for the "Open", "Print", "PrintTo" and "Preview" menu items are registered in the registry 28. In particular, note lines 3-11 in the above example. An application implements a context menu handler interface IContextMenu to add more items to a context menu for a file object. The added items may be object class specific or instance specific. FIG. 3 is a flowchart of the steps that are performed to add static verbs to context menus of an object in the preferred embodiment of the present invention. First, any predefined verbs (i.e., those that the shell supports) and additional verbs provided by a developer are registered within the registry 28 (steps 36 and 38 in FIG. 3). The operating system 26 provides functions that may be called to add entries within the registry 28. In the preferred embodiment described herein, these functions are utilized by developers to create entries in the registry 28 like those shown in lines 4-11 of the above example. These verbs are registered in the shell section of the registry and are added to context menus of the specified object type (e.g., word processing documents). The registration of the verb specifies their menu item strings. Once the verbs are registered and the context menu has been activated, menu item strings associated with the verbs are displayed in the context menu (step 40). For the above example, entries for "Open," "Print," "PrintTo" and "Preview" are all displayed as menu item strings in the context menu. A user then selects one of the menu items (step 42), and the verb for the selected menu item is activated (step 44). Path names are provided within the registry 28 for the verbs and are used to invoke the verbs in step 44 by calling the InvokeCommand() function of the IContextMenu interface (which is described in more detail below). Examples of such path names are set forth at lines 5, 7, 9 and 11 in the above example. As discussed above, an application may also register dynamic verbs. Unlike static verbs, dynamic verbs are not statically assigned to context menus. FIG. 4 is a flowchart of the steps that are performed to utilize dynamic verbs in the preferred embodiment of the present invention. The process is initiated by registering a context menu handler (step 46). An object class definition for the context menu object handler class must also be provided. In the example given above, lines 13 and 14 set forth the entries for registering the context menu handler. In particular, the class ID for the context menu handler class of objects is registered under the shellex key so that the shell knows what type of object to create when a context menu handler is needed. Instance specific context menus require a context menu handler. The context menu handler class ID is passed to a class factory, as defined within Microsoft OLE 2.01, to create an object of that class. A class factory is an object in "MICROSOFT" OLE 2.01 that supports the IClassFactory interface and is used to create instances of an object class in memory. The IClassFactory interface includes a function, CreateInstance() for creating such instances of objects classes in memory. Each context menu handler object is a DLL that allows developers to dynamically add verbs for a context menu. After the context menu handler has been registered, it is used to dynamically add verbs (step 48). This step will be described in more detail below. After the verbs have been added, the context menu is displayed with the menu items for all of the verbs, including those that have been added (step 50). A user then makes a selection that is received by the system (step 52), and the verb associated with the selected menu item is invoked by calling the InvokeCommand() function (step 54). FIG. 5 is a flowchart illustrating the steps that are performed to dynamically add a verb (step 48 in FIG. 4). A user initiates the process of adding verbs to a context menu by clicking a representation of an object with the left button of mouse 14. A message is received that indicates that the user has clicked on the object representation with the left mouse button (step 56). The class ID of the context menu handler is obtained (step 58). The class ID of the context menu handler is contained within the registry 28. The class ID in the example given above is contained in brackets on line 14. An instance of the context menu handler is created (i.e., an object of the specified object class is created) and the pointer for the IShellExtInit interface is requested (step 60). The "MICROSOFT" OLE 2.01 protocol provides interfaces for creating objects of given object classes. These functions are utilized to create an instance of a context menu handler. The IShellExtInit interface is used by the explorer to initialize shell extension objects, like the context menu handler. This interface is defined as follows.
______________________________________
# undef INTERFACE
#define INTERFACE *IShellExtInit
DECLARE.sub.-- INTERFACE.sub.-- (IShellExtInit, Iunknown)
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFRIID riid,
LPVOID*ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IShellExtInit methods ***
STDMETHOD(Initialize)
(THIS.sub.-- LPCITEMIDLIST pidlFolder, LPDDATAOBJECT
lpdobj, HKEY hkeyProgID) PURE;
};
typedef IShellExtInit * LPSHELLEXTINIT;
______________________________________
IUnknown is an interface that all objects must support by definition to comply with "MICROSOFT" OLE 2.01. Several methods from that interface are incorporated into the IShellExtInit interface. Amongst the functions added by this interface is the Initialize() function. The Initialize() function is then called to initialize the context menu handler object (step 62 in FIG. 5). A pointer to the IContextMenu interface instance provided by the context menu handler object is obtained (step 64). The IContextMenu interface is defined as follows.
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IcontextMenu, Iunknown)
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid,
LPVOID*ppvObj)
PURE; STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
STDMETHOD (QueryContextMenu) (THIS.sub.--
HMENU hmenu,
UINT indexMenu,
UINT idCmdFirst,
UINT idCmdLast,
UINT uFlags) PURE;
STDMETHOD (InvokeCommand) (THIS.sub.--
LPCMINVOKECOMMANDINFO lpici) PURE;
STDMETHOD (GetCommandString) (This
UINT idCmd,
UINT uFlags,
UINT *pwReserved,
LPSTR pszName,
UINT cchMax) PURE;
};
______________________________________
Specifically, a QueryInterface() function call is made on the context menu handler object to obtain a pointer to the instance of the IContextMenu interface provided by the context menu handler object. The IContextMenu interface includes three functions that are of interest: the QueryContextMenu() function, the InvokeCommand() function, and the GetCommandString() function. The QueryContextMenu() function allows the insertion of one or more menu items to a specified menu at a specified location. Parameters identify the menu items, the menu, and the location. The InvokeCommand() function is used to invoke a given command when the user selects the command, and the GetCommandString() function is used to get the command name or help text for a specified command. The QueryContextMenu() function is then called to add menu items to the identified context menu (step 66). These menu items and their associated verbs may then be used. The preferred embodiment of the present invention also facilitates the extension of the shell of the operating system 26 by allowing an application to add property sheet pages. This capability is provided in large part by registering a property sheet handler for each property sheet page to be added. FIG. 6 shows an example of a window 68 for displaying two property sheets, 70 and 72. The full body of the "General" property sheet 70 is visible in FIG. 6, whereas only a tab for the "Version" property sheet 70 is visible. In the example shown in FIG. 6, the property sheets are associated with a file, denoted as "WordPad". The property sheets list the names of properties of the file and the current values of the properties. The preferred embodiment of the present invention allows the addition of property sheets for objects such as the "WordPad" file. Thus, developers can create new property sheets that supplement those supported by the shell. For example, suppose that the "WordPad" object is provided by the operating system and typically only has the "General" property sheet page 70 associated with it. The preferred embodiment of the present invention allows the addition of the "Version" property sheet page by a shell extension. FIG. 7 is a flowchart of the steps that are performed to allow the addition of property sheet pages. A property sheet handler for adding property sheet pages is registered within the registry 28 (step 74 in FIG. 7). An example of such a registration is provided at lines 15 and 16 in the above example. Later when the appropriate user actions (such as clicking the right mouse button) are performed, a context menu with a "Properties . . . " command is displayed on the video display 24 (step 76). FIG. 8 shows an example of such a context menu 82 with a menu item 84 for "Properties . . . " The user then selects the "Properties . . . " menu item (step 78), and the property sheet handler is invoked to add property sheet pages (step 80). FIG. 9 is a flowchart showing in more detail the steps that are performed to add property sheet pages using the property sheet handler (see step 80 in FIG. 7). A class ID for the property sheet handler is obtained by accessing the registry 28, where the registration information for the property sheet handler is held (step 86). This retrieved class ID is then used in creating an instance of the property sheet handler and obtaining a pointer to the IShellExtInit interface (step 88). As was discussed above, this interface includes the Initialize() function. The Initialize() function is called to initialize the property sheet handler object that has been newly created (step 90). An interface pointer to the IShellPropSheetExt interface is obtained by calling the QueryInterface() function (step 92 in FIG. 9). The IShellPropSheetExt interface is defined as follows.
______________________________________
#undef INTERFACE
#define INTERFACE IShellPropSheetExt
DECLARE.sub.-- INTERFACE.sub.-- (IShellPropSheetExt, IUnknown)
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid,
LPVOID*ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IShellPropSheetExt methods ***
STDMETHOD(AddPages)
(THIS.sub.-- LPFNADDPROPSHEETPAGE lpfAddPage,
LPARAM lparam) PURE;
STDMETHOD(ReplacePage) (THIS UINT uFageID,
LPFNADDPROPSHEETPAGE lpfnReplacewith, LPARAM
lpParam) PURE;
}
______________________________________
The IShellPropSheetExt interface is used to allow property sheet extensions for adding additional property sheet pages. This interface includes the AddPages() function, which adds property sheet pages for an object. The AddPages() function is then called to add the property sheet pages (step 94). For each property sheet page that is added, a page object is created by calling a CreatePropertySheetPage() function, which is provided in the operating system 26 as part of the application program interfaces (API's) that are available. FIG. 10 is a flowchart that shows the steps that are performed to facilitate per-instance icons for objects. Representations of the per-instance icons, such as metafiles or bitmaps, are registered within the registry 28, along with an icon handler object (step 96 in FIG. 10). In the example given above, the class ID for the icon handler is registered at line 17. When the shell of the operating system 26 needs to display a representation of the object associated with the icon, it calls the icon handler to display the per-instance icon (step 98). FIG. 11 shows the steps performed to display the icon using the icon handler in more detail (see step 98 in FIG. 10). Initially, a class ID for the icon handler is obtained by accessing the registry 28 (step 100). An instance of the icon handler is created and a pointer for the IPersistFile interface instance provided by the icon handler object is obtained (step 102). Using the pointer for the IPersistFile interface (defined within Microsoft OLE 2.01) of the icon handler object that is provided, the shell calls the Load() function to initialize the icon handler object (step 104). An interface pointer for the IExtractIcon interface provided by the icon handler is obtained by calling the QueryInterface() function. The IExtractIcon interface is defined as follows.
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IExtractIcon, IUnknown)
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid,
LPVOID * ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) FURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IExtractIcon methods ***
STDMETHOD (GetIconLocation) (THIS.sub.--
UINT uFlags
LPSTR szIconFile,
UINT cchMax,
int * piIndex,
UINT * pwFlags) PURE;
STDMETHOD (ExtractIcon) (THIS.sub.--
LPCSTR pszFile,
UINT nIconIndex,
HICON *phiconLarge,
HICON *phiconSmall,
UINT nIconSize) PURE;
};
typedef IExtractIcon* LPEXTRACTICON;
______________________________________
The GetIconLocation() function returns an icon location, and the ExtractIcon function extracts an icon image from a specified file. The GetIconLocation() function is then called to obtain a location of the file that holds a representation of the icon (step 108). The ExtractIcon() function is called to extract the icon representation out of the file and use the extracted representation to display the icon with the shell (step 110). Another type of shell extension handler that may be registered in the preferred embodiment of the present invention is a copy-hook handler. An application registers to copy-hook handler so that the shell of the operating system 26 calls the copy-hook handler before the shell moves, copies, deletes, or renames a folder or printer object. The copy-hook handler does not perform the operation itself but rather provides approval for the requested operation. When the shell receives approval from the copy-hook handler, it performs the requested file system operation. FIG. 12 is a flow chart of the steps that are performed to utilize a copy-hook handler in accordance with the preferred embodiment of the present invention. Initially the copy-hook handler is registered within the registry 28 (step 112 in FIG. 12). The shell directly initializes the copy-hook handler rather than calling the IShellExtInit or IPersistFile interfaces. A copy-hook handler supports the ICopyHook interface, which is defined as follows:
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (ICopyHook, IUnknown) // s1
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid,
LPVOID * ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
STDMETHOD.sub.-- (UNIT, CopyCallback)
(THIS.sub.-- HWND hwnd, UINT wFunc,
UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs,
LPCSTR pszDestFile, DWORD dwDestAttribs) PURE;
};
typedef ICopyHook * LPCOPYHOOK;
______________________________________
The ICopyHook interface includes a CopyCallBack() function that is called and returns an integer value that indicates whether the shell should perform the requested file system operation. The method may return an integer value that encodes a "YES" response that specifies that the operation should be carried out, an integer value that encodes a "NO" response that specifies that the operation should not be performed or an integer value that encodes a "CANCEL" response that specifies that the whole operation should be canceled. For example, where a batch of files is being copied, "CANCEL" cancels the entire operation for all files on the list, whereas "NO" skips a file on the list that is being copied. Returning to FIG. 12, the shell receives a request to copy, move, rename or delete a folder or printer object (step 114). The shell then calls the CopyCallBack() function for the copy-hook handler (step 116). The function returns an integer value and the shell determines, based upon the integer value, whether to perform the operation or not (step 118). The preferred embodiment of the present invention also provides two varieties of shell extensions that concern drag-and-drop operations. The first variety is the data object extension which allows the customization of a source object during a drag-and-drop operation. The "MICROSOFT" OLE 2.01 protocol provides a uniform data transfer mechanism that is described in copending U.S. application, "Uniform Data Transfer," Ser. No. 08/199,853, filed on Feb. 22, 1994. The uniform data transfer mechanism allows the specification of a data format in which a data transfer operation is to be performed. The uniform data transfer mechanism is used during drag-and-drop operation in the preferred embodiment of the present invention. The data object extension handler allows data to be transferred in a format that is different from the data format of the source object. Thus, for example, a portion of text in a document may be dragged out of the document as a scrap and dropped in a file by using a data object extension handler that specifies that the data is to be transferred as an OLE embedding rather than a file. As a result, the scrap is dropped as an embedding. FIG. 13 is a flow chart illustrating the steps that are performed to utilize the data object extension handlers in the preferred embodiment of the present invention. Initially, the data object extension handler must be registered with the registry 28 (step 120 in FIG. 13). Data object extension handlers are registered on a per-object class basis such that multiple objects of a given class may use the same data object extension handler. A drag-and-drop operation is then initiated using the mouse 14 (step 122). As part of the drag-and-drop operation, the data object extension handler is called by the shell to extract data from the source object into the desired format (step 124). The drag-and-drop operation is then completed with the data being transferred in the appropriate data format (step 126). The preferred embodiment of the present invention additionally provides drop target extensions. Drop target extension handlers may be registered on a per-object class basis to customize the functionality of drop targets. The "MICROSOFT" OLE 2.01 protocol provides facilities for objects to register as drop targets so that they may receive drops in drag-and-drop operations. The drop target extension handlers customize the behavior of drop targets. FIG. 14 shows the steps that are performed to use a drop target extension handler in the preferred embodiment of the present invention. Initially a drop extension handler is registered on a per-object class basis with the registry 28 (step 128 in FIG. 14). A drag-and-drop operation is initiated using the mouse 14 (step 130 in FIG. 14). When the object is dropped, the shell calls the drop target extension handler to determine whether the drop should be accepted and, if accepted, to determine what steps should be performed (step 132). An example helps to illuminate the functionality that is provided by the drop target extension handlers. Suppose that a drop target is an executable file (i.e., an EXE file). In such a case, when an object is dragged and dropped on the executable file, the drop target extension handler is run. The drop target extension handler causes the executable file to run using the dropped object. For example, suppose that a document is dropped on a word processing program executable file. In such a case, the dropped target extension handler causes the word processing program to be run to edit the document that was dropped. It should be appreciated that the above-described extensions apply not only to file system objects but also to network objects that may be browsed using the shell explorer. The appropriate handlers may be registered in the registry 28 under a particular network provider or under the "Network" class. An additional extension provided by the shell of the operating system 26 is the ability to add additional name spaces that are visible to the explorer. For example, a mail folder holding mail messages may be plugged into the explorer name space. Thus, vendors may create new name spaces and simply plug the new name spaces into the explorer name space. This ability to add new name spaces is not limited to particular object types. A developer may manipulate and view objects that are visible in the explorer name space. The explorer name space is a hierarchical name space that, in the preferred embodiment, includes file system objects, control panel items, printer objects and network objects. FIG. 15 depicts an example of a user interface that is provided for the explorer. The explorer is a part of the operating system 26 that allows the user to browse the explorer name space. The user interface 134 for the explorer includes a first portion 136 that depicts the various folders in the hierarchy of the explorer name space. The second portion 138 shows the folder contained within a particular folder that is selected from amongst those in the first portion 136. The selected folders may include sub-folders or simply its own contents. For example, in FIG. 15, the second portion 138 shows in more detail the contents of folder 140. In order to incorporate a name space into the explorer name space, a developer needs to provide explorer extension handlers. The handlers are folders that are integrated into the explorer name space. These handlers act as in process server DLLs as defined within the "MICROSOFT" OLE 2.01 protocol. The explorer extension handlers must be registered within the registry 28. FIG. 16 provides a flowchart of the steps that are performed to facilitate the integration of such additional name spaces into the explorer name space. First, the explorer extension handler must be registered within the registry 28 (step 142 in FIG. 16). The explorer extension handlers may be registered under the "My Computer" directory within the explorer name space or under other file system directories. To put an extension under the "My Computer" directory, the class ID of the explorer extension handler should be registered under "HKEY.sub.-- MACHINE.backslash.Software.backslash.Windows.backslash.CurrentVersion.back slash.Explorer". When, instead, the class ID of the explorer extension handler is to be registered in a file system directory, a special file system directory should be created. The explorer extension handler is then called to display and gain access to the extended name space of the handler (step 144 in FIG. 16). FIG. 17 shows in more detail the steps that are performed to realize the displaying and accessing of the extended name space. An instance of the explorer extension handler is created and an interface pointer to the instance of the IPersistFolder that the handler provides is obtained (step 246 in FIG. 17). The IPersistFolder interface is defined as follows.
______________________________________
#undef INTERFACE
#define INTERFACE IPersistFolder
DECLARE.sub.-- INTERFACE.sub.-- (IPersistFolder, IPersist) // fld
// *** IUnknown methods ***
STDMETHOD(QueryInterface
( (THIS.sub.-- REFIID riid, LPVOID * ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IPersist methods ***
STDMETHOD(GetClassID) (THIS.sub.-- LPCLSID lpClassID) PURE;
// *** IPersistFolder methods ***
STDMETHOD(Initialize) (THIS.sub.-- LPCITEMIDLIST pidl) PURE;
};
______________________________________
The IPersistFolder interface includes the Initialize() function for initializing a shell folder object. In this case, the new name space is a shell folder object. The Initialize() function is then called (step 148). A pointer to the IShellFolder interface is obtained by calling the QueryInterface() function (step 150 in FIG. 17). The IShellFolder interface includes a number of functions that allow the explorer to view the objects within the added name space and to manipulate the objects contained therein. In particular, the IShellFolder interface is defined as follows.
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IShellFolder, IUnknown)
// *** IUnknown methods ***
STDMETHOD (QueryInterface) (THIS.sub.-- REFIID riid,
LPVOID * ppvObj)
PURE;
STDMETHOD (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IShellFolder methods ***
STDMETHOD(ParseDisplayName)
(THIS.sub.-- HWND hwndOwner, LPBC
pbcReserved, LPOLESTR lpszDisplayName,
ULONG* pchEaten, LPITEMIDLIST * ppidl, ULONG
*pdwAttributes) PURE;
STDMETHOD(EnumObjects)
(THIS.sub.-- HWND hwndOwner, DWORD grfFlags,
LPENUMIDLIST * ppenumlDList) PURE;
STDMETHOD(BindToObject) (THIS.sub.-- LPCITEMIDLIST pidl, LPBC
pbcReserved, REFIID riid, LPVOID * ppvOut) PURE;
STDMETHOD(BindToStorage)
(THIS.sub.-- LPCITEMIDLIST pidl, LPBC
pbcReserved, REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD(CompareIDs)
(THIS.sub.-- LPARAM lParam, LPCITEMIDLIST
pidl1, LPCITEMIDLIST pidl2) PURE;
STDMETHOD(CreateViewObject)
(THIS.sub.-- HWND hwndOwner, REFIID riid,
LPVOID * ppvOut) PURE;
STDMETHOD(GetAttributesOf) (THIS.sub.-- UINT cidl,
LPCITEMIDLIST *
apidl, ULONG * rgflnOut) PURE;
STDMETHOD(GetUIObjectOf)
(THIS.sub.-- HWND hwndOwner, UINT cidl,
LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut LPVOID
* ppvOut) PURE;
STDMETHOD(GetDisplayNameof)
(This.sub.-- LPCITEMIDLIST pidl, DWORD
uFlags, LPSTRRET lpName) PURE;
STDMETHOD (SetNameof) (This.sub.-- HWND hwnd([O?]wner,
LPCITEMIDLIST pidl, LPCOLESTR lpszName, DWORD uFlags,
LPITEMMIDLIST * ppidlOut) PURE;
};
______________________________________
These functions are called as needed to perform the needed behavior to view and manipulate the objects of the added name space (step 152 in FIG. 17). Of particular interest to the preferred embodiment of the present invention is the CreateViewObject() function that creates a view object that supports the IShellView interface. Also of interest in the IShellFolder interface is the GetUIObjectOff() function that creates a UI object (e.g., an icon) to be used for specified objects. The EnumObjects() function is used to enumerate the objects within the new object space. The IShellView interface is defined as follows:
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IShellView, IOleWindow)
// *** IUnknown methods ***
STDMETHOD (QueryInterface) (THIS.sub.-- REFIID riid, LPVOID FAR*
ppvObj) PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// *** IOleWindow methods ***
STDMETHOD(GetWindow) (THIS.sub.-- HWND FAR* lphwnd) PURE;
STDMETHOD(ContextSensitiveHelp)
(THIS.sub.-- BOOL fEnterMode) PURE;
// *** IShellView methods ***
STDMETHOD(TranslateAccelerator) (THIS.sub.-- LPMSG lpmsg) PURE;
STDMETMOD(EnableModeless) (THIS.sub.-- BOOL fEnable) PURE;
STDMETHOD(UIActivate) (THIS.sub.-- UINT uState) PURE;
STDMETHOD(Refresh) (THIS) PURE;
STDMETHOD(CreateViewWindow)
(THIS.sub.-- IShellView FAR *lpPrevView,
LPCFOLDERSETTINGS lpfs,
IShellBrowser FAR * psb, RECT FAR*
prcView, HWND FAR *phWnd) PURE;
STDMETHOD (DestroyViewWindow) (THIS) PURE;
STDMETHOD(GetCurrentInfo)
(THIS.sub.-- LPFOLDERSETTINGS lpfs) PURE;
STDMETHOD(ForwardControlMsg)
(THIS.sub.-- UINT id, UINT uMsg, WPARAM
wParam, LPARAM lParam,
LRESULT FAR* pret) PURE;
STDMETHOD (AddPropertySheetPages)
(THIS.sub.-- DWORD dwReserved,
LPFNADDPROPSHEETPAGE lpfn, LPARAM lparam) PURE;
STDMETHOD (SaveViewState) (THIS) PURE;
STDMETHOD(SelectItem)
(THIS.sub.-- LPCVOID lpvID, UINT uFlags) PURE;
};
______________________________________
The shell uses the IShellView interface to display information in the second portion 138 (FIG. 15) of the explorer. The explorer calls the CreateViewWindow() function to allow a name space extension to create a view window for a folder. The explorer notifies state changes by calling the UIActivate() function. The shell explorer/folder frame window that provides the first portion 136 of the explorer supports the IShellBrowser interface. This interface is defined as follows:
______________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IShellBrowser, IOleWindow)
// *** IUnknown methods ***
STDMETHOD (QueryInterface) (THIS.sub.-- REFIID riid, LPVOID FAR*
ppvObj) PURE;
STDMETHOD.sub.-- (ULONG, AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG, Release) (THIS) PURE;
// **** IOleWindow methods ***
STDMETHOD(GetWindow) (THIS.sub.-- HWND FAR* lphwnd) PURE;
STDMETHOD(ContextSensitiveHelp)
(THIS.sub.-- BOOL fEnterMode) PURE;
// *** IShellBrowser methods *** (same as IOleInPlaceFrame)
STDMETHOD(InsertMenus) (THIS.sub.-- HMENU hmenuShared,
LPOLEMENUGROUPWIDTHS lpMenuWidths) PURE;
STDMETHOD(SetMenu)
(THIS.sub.-- HMENU hmenuShared, HOLEMENU
holemenu, HWND hwndActiveObject) PURE;
STDMETHOD(RemoveMenus) (THIS.sub.-- HMENU hmenuShared) PURE;
STDMETHOD(SetStatusText)
(THIS.sub.-- LPCOLESTR lpszStatusText)
PURE;
STDMETHOD(EnableModeless) (THIS.sub.-- BOOL fEnable) PURE;
STDMETHOD(TranslateAccelerator)
(THIS.sub.-- LPMSG lpmsg, WORD wID)
PURE;
// *** IShellBrowser methods ***
STDMETHOD(BrowseObject)
(THIS.sub.-- LPMONIKER pmk, UINT wFlags)
PURE;
STDMETHOD(GetViewStateStream)
(THIS.sub.-- DWORD grfMode, LPSTREAM
FAR *ppStrm) PURE;
STDMETHOD(GetControlWindow)
(THIS.sub.-- UINT id, HWND FAR* lphwnd)
PURE;
STDMETHOD(SendControlMsg)
(THIS.sub.-- UINT id, UINT uMsg, WPARAM
wParam, LPARAM lParam, LRESULT FAR* pret) PURE;
STDMETHOD(QueryActiveShellView)
(THIS.sub.-- struct IShellView FAR**
ppshv) PURE;
STDMETHOD(OnViewWindowActive)
(THIS.sub.-- struct IShellView FAR*
ppshv) PURE;
STDMETHOD(AddViewPropertySheetPages)
(THIS.sub.-- DWORD dwReserved,
LPFNADDPROPSHEETPAGE lpfn, LPAAAM lparam) PURE;
STDMETHOD(SetToolbarItems)
(THIS.sub.-- LPTBBUTTON lpButtons, UINT
nButtons, UINT uFlags) PURE;
};
______________________________________
The shell explorer/folder frame calls its CreateViewObject() function to create an object that supports the IShellView interface. The shell explorer/folder frame calls its CreateViewWindow function to create the first portion 136 of the explorer. A pointer to the IShellBrowser interface is passed to the view object that supports the IShellView interface as a parameter to the CreateViewWindow() function call. Thus, in order to add a name space to the explorer name space, the extension handler must support the IPersistFolder and IShellFolder interfaces. In addition, each object in the new name space must support the IShellView interface. The Shell/Explorer folder frame must support the IBrowser interface. FIG. 18 is a flowchart illustrating the steps that are performed when the user opens a shell folder for an extended name space or one of the subfolders contained within the shell folder for the extended name space. Initially, the user opens the folder or subfolder in the extended name space (step 154 in FIG. 18). The folder or subfolder is typically displayed in the first area 136 (FIG. 15) of the explorer window 134. The folder or subfolder is opened by double clicking on the folder or subfolder with the mouse 14 or by selecting an open option from the file menu. A view object is then created by calling the CreateViewObject() within the IShellFolder interface (step 156 in FIG. 18). The view object knows how to display the contents of the folder or subfolder. A view window for the folder or subfolder is then created by calling the CreateViewWindow() function to create a view window for the folder or subfolder. The view object then displays information in the view window, as dictated by the folder or subfolder. Thus, for example, the contents of the folder or subfolder may he shown in a second portion 138 of the explorer window 134 (FIG. 15). The approach of the preferred embodiment of the present invention differs greatly from approaches adopted by conventional operating systems. In conventional operating systems, the shell is typically responsible for displaying any information about file system objects within a file manager. In the preferred embodiment of the present invention, in contrast, the objects are responsible for displaying their contents within the explorer. For example, each folder and subfolder within an extended name space is responsible for displaying its contents when opened using the explorer. This allows users to easily discern the contents of such folders and subfolders. While the present invention has been described with reference to a preferred embodiment thereof, those skilled in the art will appreciate that variations in form and detail may be made without departing from the intended scope of the present invention as defined in the appended claims. The shell extensions of the preferred embodiment of the present invention are described in more detail in the attached appendix. Shell Extensions About Shell Extensions In the Microsoft Windows 95 operating system, applications can extend the shell in a number of ways. A shell extension enhances the shell by providing additional ways to manipulate file objects, by simplifying the task of browsing through the file system and networks, or by giving the user easier access to tools that manipulate objects in the file system. For example, a shell extension can assign an icon to each file or add commands to the context menu and file menu for a file. Windows 95 supports the following types of shell extensions: Context menu handlers: These add items to the context menu for a particular file object. (The context menu is displayed when the user clicks a file object with the right mouse button.) Drag-and-drop handlers: These are context menu handlers that the system calls when the user drops an object after dragging it to a new position. Icon handlers: These typically add instance-specific icons for file objects. They can also be used to add icons for all files belonging to the same class. Property-sheet handlers: These add pages to the property sheet dialog box that the shell displays for a file object. The pages are specific to a class of files or a particular file object. Copy-hook handlers: These are called when a folder object is about to be copied, moved, deleted, or renamed. The handler can either allow or prevent the operation. The design of a shell extension is based on the Component Object Model in Object Linking and Embedding (OLE) version 2.0. The shell accesses an object through interfaces. An application implements the interfaces in a shell extension dynamic-link library (DLL), which is similar to an In-Process Server DLL in OLE 2.0. This <topic><article> explains how to create shell extensions and describes how the shell interacts with them. Terms You should be familiar with the following terms before proceeding: file object A file object is an item within the shell. The most familiar file objects are files and directories. However, a file object may not actually be a part of the file system--it may only appear that way. For example, printers, Control Panel applications, and network shares, servers, and workgroups are also considered to be file objects. file class Each file object is a member of a file class. The file class refers to the code that "owns" the manipulation of files of that class. For example, text files and Microsoft Word documents are examples of file classes. Each file class has specific shell extensions associated with it. When the shell is about to take an action involving a file object, it uses the file class to determine the extensions to load. handler A handler is the code that implements a particular shell extension. Registry Entries for a Shell Extension A shell extension must be registered in the Windows registry. The class identifier of each handler must be registered under the HKEY.sub.-- CLASSES.sub.-- ROOT.backslash.CLSID key. The CLSID key contains a list of class identifier key values such as {00030000-0000-0000-C000-000000000046}. Each class identifier key is a globally unique identifier (GUIDs) generated with the UUIDGEN tool. Within each class identifier key, the handler adds an InProcServer32 key that gives the location of the handler's dynamic-link library (DLL). It is best to give the complete path for the handler; using the complete path keeps the handler independent of the current path and speeds up the load time for the DLL. An application that creates and maintains files, such as a spreadsheet, word processor, or database application, usually registers two additional entries in the registry; a file association entry and a key name. The file association entry maps a file extension to an application identifier. For example, a word-processing application might register the following key under HKEY.sub.-- CLASSES.sub.-- ROOT:
______________________________________
HKEY.sub.-- CLASSES.sub.-- ROOT
.doc=AWordProcessor
______________________________________
The key name (.doc) specifies the file extension, and the value of the key (AWordProcessor) denotes the key name that contains the information about the application that handles the file extension. The value of the key name is the second registry entry made by an application that handles files.
______________________________________
HKEY.sub.-- CLASSES.sub.-- ROOT
AWordProcessor = A Word Processor
shell
open
command = c:.backslash.aword.backslash.aword.exe %1
print
command = c:.backslash.aword.backslash.aword.exe %1
printTo
command = c:.backslash.aword.backslash.aword.exe %1 %2
preview = Pre&view
command - c:.backslash.aword.backslash.aword.exe /r %1
shellex
ContextMenuHandlers = ExtraMenu
ExtraMenu = {00000000-1111-2222-3333-00000000000001}
PropertySheetHandlers = SummaryInfo
SummaryInfo = {00000000-1111-2222-3333-00000000000002}
IconHandler = {00000000-1111-2222-3333-00000000000003}
______________________________________
The commands in the shell section of the registry are added to the context menus of the corresponding files. The printTo command is also used when the user drops a document onto a printer. To avoid conflicts with other classes, you must use real GUIDs, not the sample strings shown in the previous example. The information that the shell uses to associate a shell extension handler with a file type is stored under the shellex key. The shell also uses several other special keys--*, Folder, Drives, Printers, and keys for network providers--under HKEY.sub.-- CLASSES.sub.-- ROOT to look for shell extensions: You can use the * key to register handlers that the shell calls whenever it creates a context menu or property sheet for a file object. For example:
______________________________________
HKEY.sub.-- CLASSES.sub.-- ROOT
* = *
shellex
ContextMenuHandlers = ExtraMenu
ExtraMenu = {00000000-1111-2222-3333-00000000000001}
PropertySheetHandlers = SummaryInfo
SumaryInfo = {00000000-1111-2222-3333-00000000000002}
______________________________________
The shell uses instances of the ExtraMenu and SummaryInfo handlers to add to the context menus and property sheets for every file object. You can use the the Folder key to register a shell extension for directories in the file system. You can register context-menu handlers, copy-hook handlers, and property-sheet handlers in the same way you register these handlers for the * key. An additional handler, the drag-drop handler, applies only to the Folder and Printers keys. For example:
______________________________________
Folder = Folder
shellex
DragDropHandlers = ADDHandler
ADDHandler = {00000000-1111-2222-3333-00000000000004}
CopyHookHandlers = ACopyHandler
ACopyHandler = {00000000-1111-2222-3333-00000000000005}
______________________________________
You can use the Drives key for the same registrations as the Folder key, but the Drives key is called only for root paths, for example, C:.backslash.. The Printers key allows the same registrations as the Folder key, but uses additional handlers for printer events, deletion or removal of printers (through the copy-hook handler), and printer properties (with property-sheet handlers and context-menu handlers). How the Shell Accesses Shell Extension Handlers The shell uses two interfaces to initialize instances (objects created by IClassFactory::CreateInstance) of shell extensions: IShellExtInit and IPersistFile. The shell uses the IShellExtInit interface to initialize instances of context-menu handlers, drag-drop handlers, and property-sheet handlers. The shell uses IPersistFile to initialize instances of icon handlers. This interface is same as the IPersistFile interface in OLE 2.0. The IShellExtInit interface adds one member function, Initialize, to the standard IUnknown interface. A handler's initialize function should keep a copy of the parameters that the shell passes to the function for use later. For example:
__________________________________________________________________________
STDMETHOD SHE.sub.-- ShellExtInit.sub.-- Initialize(LPSHELLEXTINIT psxi,
LPCITEMIDLIST pidlFolder, LPDATAOBJECT pdtobj, HKEY hkeyProgID)
PSHELLEXTSAMPLE this = PSXI2PSMX(psxi);
// Initialize can be called more than once.
if (this->.sub.-- pdtobj) {
this->.sub.-- pdtobj->lpVtbl->Release(this->.sub.-- pdtobj);
}
if (this->.sub.-- hkeyProgID) {
RegCloseKey(this->.sub.-- hkeyProgID);
}
// Duplicate the pdtobj pointer, then update the usage count.
if (pdtobj) {
this->.sub.-- pdtobj = pdtobj;
pdtobj->lpVtbl->AddRef(pdtobj);
}
// Duplicate the registry handle.
if (hkeyProgID) {
RegOpenKey(hkeyProgID, NULL, &this->.sub.-- hkeyProgID);
}
return NOERROR;
}
__________________________________________________________________________
A shell extension handler must implement three functions: an entry point (often called DIIMain or LibMain), DIICanUnloadNow, and DIIGetClassObject. The entry point is standard for any 32-bit DLL; it usually saves the handle to the DLL for future use. The handle must be stored in a per-instance variable. The following example shows a typical entry point for a handler:
__________________________________________________________________________
BOOL APIENTRY LibMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
switch(dwReason) {
case DLL.sub.-- PROCESS.sub.-- ATTACH:
g.sub.-- hmodThisDll = hDll; // must be per-instance.
break;
case DLL.sub.-- PROCESS.sub.-- DETACH:
case DLL.sub.-- THREAD.sub.-- DETACH:
case DLL.sub.-- THREAD.sub.-- ATTACH:
break;
default:
break;
}
return TRUE;
}
__________________________________________________________________________
The DIICanUnloadNow and DIIGetClassObject functions are essentially the same as they would be for any In-Proc Server DLL in OLE 2.0. DIICanUnloadNow is straightforward:
______________________________________
STDAPI DllCanUnloadNow(void)
// g.sub.-- cRefThisDll must be placed in the per-insance data section.
return ResultFromScode((g.sub.-- cRefThisDll==0) ? S.sub.-- OK : S.sub.--
FALSE);
}
______________________________________
DIIGetClassObject needs to expose the class factory for the object in the DLL. For more information on exposing the class factory, see the OLE 2.0 Programmer's Reference. The following example shows how to expose the class factory:
__________________________________________________________________________
extern CDefClassFactory * NEAR PASCAL CDefClassFactory.sub.-- Create(
LPFNCREATEINSTANCE lpfnCI, UINT EAR * pcRefDll, REFIID riidInst);
// DllGetClassObject - DLL entry point used by most In-Proc Server DLLs.
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR*
ppvOut)
*ppvOut = NULL; // Assume failure
if (IsEqualIID(rclsid, &CLSID.sub.-- ShellExtSample)) {
if (ISEqualIID(riid, &IID.sub.-- IClassFactory))
.vertline..vertline. IsEqualIID(riid, &IID.sub.-- IUnknown)) {
CDefClassFactory * pacf = CDefClassFactory.sub.-- Create(
ShellExtSample.sub.-- CreateInstance, &g.sub.-- cRefThisDll,
NULL);
if (pacf) {
(IClassFactory FAR *)*ppvOut = &pacf->cf;
return NOERROR;
}
return ResultFromScode(E.sub.-- OUTOFMEMORY);
}
return ResultFromScode(E.sub.-- NOINTERFACE);
} else {
return ResultFromScode(CLASS.sub.-- E.sub.-- CLASSNOTAVAILABLE);
}
}
__________________________________________________________________________
Item Identifiers and Identifier Lists The Windows 95 shell provides an object called an item identifier (item ID), which is a variable-length byte stream that contains information for identifying a file object within a folder. An item ID contains only persistent values such as pointers to data structures, window handles, or atoms. This is because the shell may store an item ID in persistent storage (that is, on disk) and use it later. The Windows header files define an item ID as follows:
______________________________________
typedef struct .sub.-- SHITEMID {
USHORT cb; // size, in bytes, of the item ID
BYTE abID[1];
// item ID (variable length)
} SHITEMID, FAR* LPSHITEMID;
typedef const SHITEMID FAR * LPCSHITEMID;
______________________________________
An item ID may also contain information that helps improve the efficiency with which you can manipulate the file object. For example, an item ID might contain the file object's display name or data used for sorting the object. The shell uses only the first two bytes of an item ID, which specify the ID's size. The remaining data in an item ID is used only by the handler that created the ID. The shell often concatenates item IDs and appends a terminating NULL character, creating an item ID list. A simple item ID list contains only one item ID; a complex item ID list contains multiple item IDs. For consistency, the shell always passes the address of an item ID list to a handler even when the handler can only use a single item ID. The Windows header files define an item ID list as follows:
______________________________________
typedef struct .sub.-- ITEMIDLIST { // idl
SHITEMID mkid;
} ITEMIDLIST, FAR* LPITEMIDLIST;
typedef const ITEMIDLIST FAR* LPCITEMIDLIST;
______________________________________
Context Menu Handlers A context menu handler is a shell extension that adds menu items to any of the shell's context menus. TV are two types of context menu handlers, which have different purposes but the same implementation: context menu extensions are used when the user right clicks on a file object; drag-drop handlers are used when the user drags a file object using the right mouse button. This <section> describes the types of context menu handlers, how they are used, how they are added to the registry, and the interfaces they must implement. Context Menu Extensions When the user clicks the right mouse button on an item within the shell's name space (e.g., file, directory, saver, work-group, etc.), it creates the default context menu for its type, then loads context menu extensions that are registered for that type (and its base type) so that they can add extra menu items. Those context menu extensions are registered at the following location: HKCR.backslash.{ProgID}.backslash.shellex.backslash.ContextMenuHandlers The IContextMenu Interface An application implements a context-menu handler interface, IContextMenu, to add menu items to the context menu for a file object. The shell displays the object's context menu when the user clicks the object with the right mouse button. The menu items can be either class-specific (that is, applicable to all files of a particular type) or instance-specific (that is applicable to an individual file). When the user right-clicks a file object, the system passes the address of the object's context menu to the context-menu handler, which should use the handle only to add items to the menu. Your handler should not delete or modify existing menu items because other handlers may add items either before or after yours does. In addition, the shell adds items to the menu after all context-menu handlers have been called. Context-menu handlers are entered in the registry under the shellex key within an application's information area. The ContextMenuHandlers key lists the names of subkeys that contain the CLSID of each context-menu handler, for example:
______________________________________
ContextMenuHandlers = ExtraMenu
ExtraMenu = {00000000-1111-2222-3333-00000000000001}
______________________________________
You can register multiple context-menu handlers for a file type. In this case, the order of the subkey names in the ContextMenuHandlers key determines the order of the context menu's items. In addition to the standard IUnknown member functions, the context-menu handler interface uses three member functions: QueryContextMenu InvokeCommand GetCommandString When the user selects one of the menu items added by a context-menu handler, the shell calls the handler's IContextMenu::InvokeCommand member function to let the handler process the command. If you register multiple context-menu handlers for a file type, the value of the ContextMenuHandlers key determines the order of the commands. When the system is about to display a context menu for a file object, the system calls the context-menu handler's QueryContextMenu member function. The context-menu handler inserts menu items by position (MF.sub.-- POSITION) directly into the context menu by calling the InsertMenu function. Menu items must be string items (MF.sub.-- STRING), as the following example demonstrates:
__________________________________________________________________________
STDMETHODIMP SHE.sub.-- ContextMenu.sub.-- QueryContextMenu(LPCONTEXTMENU
pctm,
HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast,
UINT uFlags)
UINT idCmd = idCmdFirst;
if (idCmdFirst+2 > idCmdLast)
return ResultFromScode(E.sub.-- FAIL);
InsertMenu(hmenu, indexMenu++, MF.sub.-- STRING .vertline. MF.sub.--
BYPOSITION,
idCmd++, "Check H&DROP (menuext)");
InsertMenu(hmenu, indexMenu++, MF.sub.-- STRING .vertline. MF.sub.--
BYPOSITION,
idCmd++, "Check H&NRES (menuext)");
return ResultFromScode(MAKE.sub.-- SCODE(SEVERITY.sub.-- SUCCESS,
FACILITY.sub.-- NULL,
(USHORT) 2));
}
__________________________________________________________________________
The system calls the InvokeCommand member function when the user selects a menu item that the context-menu handler added to the context menu. The InvokeCommand function in the following example handles the commands associated with the menu items added by the previous example:
__________________________________________________________________________
STDEMETHODIMP SHE.sub.-- ContextMenu.sub.-- InvokeCommand(LPCONTEXTMENU
pctm,
HWND hwnd, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam,
int iShowCmd)
PSHELLLEXTSAMPLE this = PCTM2PSMX(pctm);
HRESULT hres = ResultFromScode(E.sub.-- INVALIDARG); // assume error
// No need to support string-based command.
if (!HIWORD(pszCmd)) {
UINT idCmd = LOWORD(pszCmd);
switch(idCmd) {
case IDM.sub.-- HDROP:
hres = DoHDROPCommand(hwnd, pszWorkingDir, pszCmd,
pszParam, iShowCmd);
break;
case IDM.sub.-- HNRES:
hres = DoHNRESCommand(hwnd, pszWorkingDir, pszCmd,
pszParam, iShowCmd);
break;
}
}
return hres;
}
__________________________________________________________________________
Windows calls the GetCommandString member function to get a language-independent command string or the help text for a context menu item. Drag-Drop Handlers Drag-drop handlers implement the IContextMenu interface. In fact a drag-drop handler is simply a context-menu handler that affects the menu the shell displays when a user drags and drops a file object with the right mouse button. Since this menu is called the drag-drop menu, shell extensions that add items to this menu are called drag-drop handlers. Drag-drop handlers work in the same way as context-menu handlers. Copy Hook Handlers A copy-hook handler is a shell extension that the shell calls before moving, copying, deleting, or renaming a folder object. The copy-hook handler does not perform the task itself, but provides approval for the task. When the shell receives approval from the copy-hook handler, it performs the actual file system operation (move, copy, delete, or rename). Copy-hook handlers are not informed about the success of the operation, so they cannot monitor actions that occur to folder objects. The shell initializes the copy-hook handler interface directly, that is, without using an IShellExtInit or IPersistFile interface first. A folder object can have multiple copy-hook handlers. The copy-hook handler interface has one member function, CopyCallBack, in addition to the standard IUnknown member functions. The shell calls the CopyCellBack member function before it copies, moves, renames, or deletes a folder object. The function returns an integer value that indicates whether the shell should perform the operation. The shell will call each copy-hook handler registered for a folder object until either all the handlers have been called, or any handler returns IDCANCEL. The handler can also return IDYES to specify that the operation should be carried out, or IDNO to specify that the operation should not be performed. Icon Handlers An application can use the shell's icon interface to customize the icons that the shell displays for the application's file types. The icon interface also allows an application to specify icons for folders and subfolders within the application's file structure. An application can specify icons for its file types in two ways. The simplest way is to specify a class icon to be used for all files of a particular file type by adding a DefaultIcon key to the registry under the program information. The value of this key specifies the executable (or DLL) that contains the icon, and the index of the icon with the file. For example: DefaultIcon=c:/Mydif/Myapp.exe,1 One of the advantages of using a class icon is that it requires no programming; the shell handles displaying the icon for the class. Windows 95 adds a new value, %1, for the DefaultIcon key. This value denotes that each file instance of this type can have a different icon. The application must supply an icon handler for the file type and add another entry, IconHandler, to the shellex key for the application. An application can have only one IconHandler entry. The value of the IconHandler key denotes the CLSID of the icon handler, for example:
______________________________________
shellex
IconHandler = {00000000-1111-2222-3333-00000000000003}
DefaultIcon = %1
______________________________________
To have customized icons, an application must provide an icon handler that implements the IExtractIcon interface. The system takes the following steps when it is about to display an icon for a file type that has instance-specific icons: 1. Retrieves the class identifier of the handler. 2. Creates an IClassFactory object by calling the DllGetClassObject entry of the specified DLL. 3. Calls IClassFactory::CreateInstance with IID.sub.-- IPersistFile to create its instance. 4. Initializes the instance by calling the IPersistFile::Load member function. 5. Uses the QueryInterface member function to get to the IExtractIcon interface. 6. Calls the IExtractIcon interface's GetIconLocation and ExtractIcon member functions. The IExtractIcon interface has two member functions in addition to the usual IUnknown member functions: GetIconLocation ExtractIcon The system calls the GetIconLocation member function to get the location of an icon to display. Typically, the icon location is an executable or DLL filename, but it can be any file. The following example saves the filename passed to the Load member function of IPersistFile, and tells the shell where to find the icon to display:
__________________________________________________________________________
STDMETHODIMP SHE.sub.-- PersistFile.sub.-- Load(LPPERSISTFILE
pPersistFile,
LPCOLESTR lpszFileName, DWORD grfMode)
// Get a pointer to my class
PSHELLEXTSAMPLE this - PPSF2PSMX(pPersistFile);
int iRet = WideCharToMultiByte(CP.sub.-- ACP, WC.sub.-- SEPCHARS,
lpszFileName,
-1, this->.sub.-- szFile, sizeof(this->.sub.-- szFile), NULL, NULL);
// Copy the filename to a buffer.
if (iRet==0) {
LPSTR psz=this->.sub.-- szFile;
while(*psz++ = (char)*lpszFileName++);
}
return NOERROR;
}
STDMETHODIMP SHE.sub.-- ExtractIcon.sub.-- GetIconLocation(LPEXTRACTICON
pexic,
UINT uFlags, LPSTR szIconFile, UINT cchMax, int FAR * piIndex,
UINT FAR * pwFlags)
{
PSHELLEXTSAMPLE this = PEXI2PSMX(pexic);
if (this->.sub.-- szFile[0]) {
GetPrivateProfileString("IconImage", "FileName",
"shell32.dll",szIconFile, cchMax, this->.sub.-- szFile);
*piIndex = (int) GetPrivateProfileInt("IconImage", "Index",
0, this->.sub.-- szFile);
} else {
lstrcpy(szIconFile, "shell32.dll");
*piIndex = -10;
}
*pwFlags = 0;
return NOERROR;
}
__________________________________________________________________________
The system calls the ExtractIcon member function when it needs to display an icon for a file that does not reside in an executable or DLL. Applications usually have the file icons in their executables or DLLs, so icon handlers can simply implement this member function as a return-only function that returns E.sub.-- FAIL. When the icon for a file is in a separate .ICO file (or any other type of file), the icon handler must extract the icon for the shell and return it in this member function. Property Sheet Handlers Another way the shell can be extended is by custom property sheets. When the user selects the properties for a file, the shell displays a standard property sheet. If the registered file type has a property-sheet handler, the shell will allow the user to access additional sheets that the handler provides. Property-sheet handlers implement the IShellPropSheetExt interface. Property-sheet handlers are entered in the registry under the shellex key, within an application's information area. The PropertySheetHandlers key lists the names of subkeys that contain the class identifier of each context-menu handler. For example:
______________________________________
PropertySheetHandlers = SummaryInfo
SummaryInfo = (00000000-1111-2222-3333-00000000000002)
______________________________________
You can register multiple property-sheet handlers for a file type. In this case, the order of the subkey names in the PropertySheetHandlers key determines the order of the additional property sheets. You can use a maximum of 24 (the value of MAXPROPPAGES) pages in a property sheet. Adding Property Sheet Pages The property-sheet handler uses the AddPages member function in addition to the usual IUnknown member functions. The system calls the AddPages member function when it is about to display a property sheet. The system calls each property-sheet handler registered to the file type to allow the handlers to add pages to the property sheets. The following example shows how to implement the AddPages member function.
______________________________________
STDMETHODIMP CSamplePageExt::
AddPages(LPFNADDPROPSHEETPAGE lnpfAddPage,
LPARAM lParam)
PROPSHEETPAGE psp;
HPROPSHEETPAGE hpage;
psp.dwSize = sizeof(pap); ,, no extra data.
psp.ds,Flags = PSP.sub.-- USEREPARENT .vertline. PSP.sub.-- USERELEASEFUNC
;
psp.hInstance = (INSTANCE)g.sub.-- hmodThisD11;
psp.pszTemplate = MAKEINTRESOURCE(DLG.sub.-- ESPAGE);
psp.pfnDlgProc = FSPage.sub.-- DlgProc;
psp.pcRefParent = &g.sub.-- cRefThisD11;
psp.pfnRelease = FSPage.sub.-- ReleasePage;
psp.lParam = (LPARAM)hdrop;
hpage = CreatePropertySheetPage(&psp);
if (hpage) {
if (!lpfnLAddPage(hpage, lParam)}
DestroyPropertySheetPage(hpage);
}
return NOERROR;
}
______________________________________
Replacing Control Panel Pages The ReplacePage member function is called only by control panels. It allows you to replace the property sheet of a standard control panel with a custom page. For example, if a mouse manufacturer adds extra buttons to it's mouse, the manufacturer can replace the standard mouse control panel's "Buttons" property sheet page. The ReplacePage member function is not called by the shell because the shell does not have any property sheet pages that can be replaced by a shell extension. Currently, only control panels call this member function, but other property sheet suppliers could use this member function to allow their property sheet pages to be replaced. Each property sheet handler that allows a property sheet page to be replaced must specify the registry location where other handlers that replace pages must register themselves. For the standard control panel applications, this location is defined by the REGSTR.sub.-- PATH.sub.-- CONTROLSFOLDER macro in the REGSTR.H file. The macro defines the key under the HKEY.sub.-- LOCAL.sub.-- MACHINE key in which all control panel property sheet page replacement handlers must register. For example, a property sheet handler that needs to replace a property sheet page for the mouse control panel would register a property sheet extension handler in the following registry location:
______________________________________
HKEY.sub.-- LOCAL.sub.-- MACHINE
REGSTR.sub.-- PATH.sub.-- CONTROLSFOLDER
Mouse
shellex
PropertySheetHandlers = NewMousePage
. . .
NewMousePage = (00000000-1111-2222-3333-00000000000002)
______________________________________
In addition, a property sheet handler that allows replaceable pages must define identifiers for each page that can be replaced. The standard control panels define this location in the REGSTR.H file and CPLEXT.H files. In REGSTR.H, the macro REGSTR.sub.-- PATH.sub.-- CONTROLSFOLDER defines the key under the HKEY.sub.-- LOCAL.sub.-- MACHINE key in which all control panel property sheet page replacement handlers must register. CPLEXT.H defines the subkey for each control panel that contains a replaceable property sheet page. The subkey is /Mouse for a mouse control panel application, and /Keyboard for a keyboard control panel application. The standard control panel applications s define these in CPLEXT.H. For example CPLPAGE.sub.-- MOUSE.sub.-- BUTTONS defines the identifier for the mouse control panel's buttons page, and CPLPAGE.sub.-- KEYBOARD.sub.-- SPEED defines the identifier for the keyboard control panel's speed page. Reference Context Menu Interfaces and Members IContextMenu Interface that enables the shell to retrieve extensions to context menus. The IContextMenu interface has the following member functions:
______________________________________
QueryContextMenu
Adds commands to a context menu.
InvokeCommand
Carries out a menu command, either in response
to user input or otherwise.
GetCommandString
Retrieves the language-independent name of a menu
command, or the help text for a menu command.
______________________________________
Like all OLE interfaces, IContextMenu also includes the QueryInterface, AddRef, and Release member functions. IContextMenu::QueryContextMenu
______________________________________
HRESULT
STDMETHODCALLTYPE ICcontextMenu::QueryContextMenu[
LPCONTEXTMENU pIface, HMENU hmenu, UINT indexMenu,
UINT idCmdFirst, UINT idCmdLast, UINT uFlags
];
______________________________________
Adds menu items to the specified menu. The menu items should be inserted at a specified position in the menu, and their menu item identifiers must be in a specified range. Returns an HRESULT in which, if successful, the code field contains the menu-identifier offset of the last menu item added. pIface Address of the IContextMenu interface. In C++, this parameter is implicit. hmenu Handle of the menu. The handler should specifying this handle when calling the InsertMenu or InsertMenuItem function. indexMenu Zero-based position at which to insert the first menu item. idCmdFirst and idCmdLast Minimum and maximum values that the handler can specify for menu item identifiers. The actual identifier of each menu item should be idCmdFirst plus a menu-identifier offset in the range 0 through (idCmdLast-idCmdFirst). uFlags Value specifying zero or more of the following flags:
______________________________________
CMF.sub.-- DEFAULTONLY
Specifies that the user is invoking
the default action
typically by double-clicking.
A context menu
extension or drag-drop handler
should not add any
menu items if this flag is specified.
A name-space
extension should add only the
default item, if any.
CMF.sub.-- VERBSONLY
Context menu handlers should
ignore this flag. This
flag is specified if thc context menu
is for a shortcut object.
CMF.sub.-- EXPLORER
Context menu handlers should
ignore this flag. This
flag is specified if the context
menu is for an object
in the left pane of the explorer.
______________________________________
The remaining bits of the low-order word are reserved by the system. The high-order word may be used for context-specific communications. IContextMenu::InvokeCommand
______________________________________
HRESULT STDMETHODCALLTYPE IContextMenu::InvokeCommand(
LPCONTEXTMENU pIface, LPCMINVOKECOMMANDINFO lpici);
______________________________________
Carries out the command associated with a context menu item. Returns NOERROR if successful, an OLE-defined error code otherwise. pIface Address of the IContextMenu interface. In C++, this parameter is implicit. lpici Address of a CMINVOKECOMMANDINFO structure containing information about the command. The shell calls this member function when the user chooses a command that the handler added to a context menu. This member function may also be called programmatically, without any corresponding user action. IContextMenu::GetCommandString
______________________________________
HRESULT
STDMETHODCALLTYPE IContextMenu::GetCommandString(
LPCONTEXTMENU pIface, UINT idCmd, UINT uType,
UINT *pwReserved, LPSTR pszName, UINT cchMax);
______________________________________
Retrieves the language-independent command name of a menu item or the help text for a menu item. Returns NOERROR if successful, an OLE-defined error code otherwise. pIface Address of the IContextMenu interface. In C++, this parameter is implicit. idCmd Menu-item identifier offset. uFlags Value specifying the information to retrieve. Can be one of these values:
______________________________________
GCS.sub.-- VERB
Return the language-independent
command name for the menu item.
GCS.sub.-- HELPTEXT
Return the help text for the menu item.
______________________________________
pwReserved Reserved Applications must specify NULL when calling this member function; handles must ignore this parameter when called. pszName and cchMax Address and size of the buffer that receives the null-terminated string. The language-independent command name is a name that can be passed to the IContextMenu::InvokeCommand member function to invoke a command programmatically. The help text is a description that the Explorer displays in its status bar, and should be reasonably short (under 40 characters). Copy Hook Interfaces and Members ICopyHook Interface that allows a copy hook hander to prevent a folder or printer object from being copied, moved, deleted, or renamed. The shell calls a copy hook handler whenever file system directories are about to be copied, moved, deleted, or renamed, as well as when the status of a printer is about to change. The shell initializes the copy-hook handler interface directly, that is, without using the IShellExtInit interface first. A folder object can have multiple copy-hook handlers. A copy-hook handler interface has one member function, CopyCallBack, in addition to the standard QueryInterface, AddRef, and Release member functions. ICopyHook::CopyCallback HRESULT STDMETHODCALLTYPE CopyCallback(ICopyHook FAR * pCopyHook, HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs); Either allows the shell to carry out a copy, move, rename, or delete operation on a folder object, or prevents the shell from carrying out the operation. The shell calls each copy-hook handler registered for a folder object until either all the handlers have been called, or any handler returns IDCANCEL. Returns an integer value that indicates whether the shell should perform the operation. It can be one of these values:
______________________________________
Value Meaning
______________________________________
IDYES Allow the operation
IDNO Prevent the operation on this file,
but continue with any other
operations (for example, a batch copy operation)
IDCANCEL
Prevent the current operation and
cancel any pending operations
______________________________________
pCopyHook Address of the ICopyHook interface. In C++, this parameter is implicit. hwnd Handle of the window that the copy-hook handler should use as the parent window for any user interface elements the handler may need to display. The member function should ignore this parameter if FOF.sub.-- SILENT is specified. wFunc Operation to perform. Can be one of the following values:
______________________________________
Value Meaning
______________________________________
FO.sub.-- DELETE
Delete the file specifed by pszSrcFile.
FO.sub.-- RENAME
Rename the file specified by pszSrcFile.
FO.sub.-- MOVE
Move the file specified by pszSrcFile to
the location specified by pszDestFile.
FO.sub.-- COPY
Copy the file specifled by pszSrcFile to
the location specified by pszDestFile.
PO.sub.-- DELETE
Delete the printer specified by pszSrcFile.
PO.sub.-- RENAME
Rename the printer specified by pszSrcFile.
PO.sub.-- PORTCHANGE
Change the printer port.
The pszSrcFile and pszDestFile
parameters contain double null-
terminated lists of
strings. Each list contains the printer
name followed by
the port name. The port name in
pszSrcFile is the
current printer port; the port name in
pszDestFile is the new printer port.
PO.sub.-- REN.sub.-- PORT
Combination of PO.sub.-- RENAME and
PO.sub.-- PORTCHANGE.
______________________________________
wFlags Flags that control the operation. Can be a combination of the following values:
______________________________________
Value Meaning
______________________________________
FOF.sub.-- ALLOWUNDO
Preserve undo information,
if possible.
FOF.sub.-- CONFIRMMOUSE
Not implemented.
FOF.sub.-- FILESONLY
Not implemented. The shell calls
a copy hook
handler only for folder objects,
not files.
FOF.sub.-- MULTIDESTFILES
The SHFileOperation function
specified multiple destination
files (one for each source
file) rather than one directory
where all the
source files are to be deposited.
A copy-hook
handler typically ignores
this flag.
FOF.sub.-- NOCONFIRMATION
Respond with "yes to all"
for any dialog box
that is displayed.
FOF.sub.-- NOCONFIRMMKDIR
If the operation requires a
new directory to be
created, do not confirm the
creation. to create
any needed directories.
FOF.sub.-- RENAMEONCOLLISION
In a move, copy, or rename
operation, if a file
of the target name already
exists, give the file
being operated on a new
name (such as "Copy
#1 of . . .").
FOF.sub.-- SILENT
Do not display a progress
dialog box.
FOF.sub.-- SIMPLEPROGRESS
Display a progress dialog box,
but the dialog
box does not show the names
of the files.
______________________________________
pszSrcFile Address of a string that contains the name of the source file. dwSrcAttribs Attributes of the source file. Can be a combination of any of the file attribute flags (FILE.sub.-- ATTRIBUTE.sub.-- *) defined in the Windows header files. pszDestFile Address of a string that contains the name of the destination file. dwDestAttribs Attributes of the source file. Can be a combination of any of the file attribute flags (FILE.sub.-- ATTRIBUTE.sub.-- *) defined in the Windows header files. Icon Interfaces and Members IExtractIcon Interface that enables the shell to retrieve icons for file objects or folders. The IExtractIcon interface has the following member functions:
______________________________________
GetIconLocation
Retrieves the icon location for a file object.
ExtractIcon
Extracts an icon from the specified location.
______________________________________
Like all OLE interfaces, IExtractIcon also includes the QueryInterface, AddRef, and Release member functions. IExtractIcon::GetIconLocation
______________________________________
HRESULT STDMETHODCALLTYPE IExtractIcon::GetIconLocation(
LPEXTRACTICON pIface, UINT uFlags, LPSTR szIconFile,
UINT cchMax, int *piIndex, UINT *pwflags
);
______________________________________
Retrieves the location and index of an icon. Returns NOERROR if the function returned a valid location, S.sub.-- FALSE if the shell should use a default icon. pIface Address of the IExtractIcon interface. In C++, this parameter is implicit. uFlags Flags. Can be zero or the following value:
______________________________________
GIL.sub.-- OPENICON
Specifies that the icon is for a folder that is
______________________________________
open.
szIconFile and cchMax Address and size of the buffer that receives the icon location. The icon location is a null-terminated string that typically specifies the name of an icon file. piIndex Address of an integer that receives the icon index. pwFlags Address of an unsigned integer that receives zero or more of these values:
______________________________________
GIL.sub.-- SIMULATEDOC
Specifies that the shell
should create a document icon
using the specified icon.
GIL.sub.-- PERINSTANCE
Specifies that each file object of this
class has its own icon.
GIL.sub.-- PERCLASS
Specifies that all file objects
of this class have the same icon.
______________________________________
IExtractIcon::ExtractIcon
______________________________________
HRESULT STDMETHODCALLTYPE IExtractIcon::ExtractIcon(
LPEXTRACTICON pIface, LPCSTR pszFile, UINT nIconIndex,
HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize
);
______________________________________
Extracts an icon image from the specified location. Returns NOERROR if the function extracted the icon, S.sub.-- FALSE if the caller should extract the icon. pIface Address of the IExtractIcon interface. In C++, this parameter is implicit. pszFile Address of a null-terminated string specifying the icon location. nIconIndex Icon index. phiconLarge and phiconSmall Addresses of variables that receive the handles of the large and small icons, respectively. nIconSize Value specifying size (width or height) of the large icon required, in pixels. The width of an icon always equals its height. The icon location and index are the same values returned by the IExtractIcon::GetIconLocation member function. If this function returns S.sub.-- FALSE, these values must specify an icon filename and index. If this function does not return S.sub.-- FALSE, the caller should make no assumptions about the meanings of the pszFile and nIconIndex parameters. Property Sheet Interfaces and Members IShellPropSheetExt Interface that allows a property sheet hander to add or replace pages in the property sheet for a file object. The IShellPropSheetExt interface has the following member functions:
______________________________________
AddPages
Adds one or more pages to a property sheet for a file object.
ReplacePage
Replaces a page in a property sheet
for a control panel object.
______________________________________
Like all OLE interfaces, IShellPropSheetExt also includes the QueryInterface, AddRef, and Release member functions. IShellPropSheetExt:AddPages
__________________________________________________________________________
HRESULT STDMETHODCALLTYPE AddPages(IShellPropSheetExt FAR * pProp,
LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
__________________________________________________________________________
Adds one or more pages to a property sheet that the shell displays for a file object. When it is about to display the property sheet, the shell calls the AddPages member function of each property sheet handler registered to the file type. Returns NOERROR if successful, an OLE-defined error value otherwise. pProp Address of the IShellPropSheetExt interface. In C++, this parameter is implicit. lpfnAddPage Address of a function that the property sheet handler calls to add a page to the property sheet. The function takes a property sheet handle returned by the CreatePropertySheetPage function, and the lParam parameter passed to the AddPages member function. lParam Parameter to pass to function specified by lpfnAddPage. For each page it needs to add to a property sheet, a property sheet handler fills a PROPSHEETPAGE structure, calls CreatePropertySheetPage, and then calls the function specified by lpfnAddPage. IShellPropSheetExt::ReplacePage
__________________________________________________________________________
HRESULT STDMETHODCALLTYPE ReplacePage(ISHellPropSheetExt FAR * pProp,
UINT uPageID, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
__________________________________________________________________________
Replaces a page in a property sheet for a control panel object Returns NOERROR if successful, an OLE-defined error value otherwise. pProp Address of the IShellPropSheetExt interface. In C++, this parameter is implicit. uPageID Identifier of the page to replace. The values for uPageID for control panels can be found in the CPLEXT.H header file. lpfnReplacePage Address of a function that the property sheet handler calls to replace a page to the property sheet. The function takes a property sheet handle returned by the CreatePropertySheetPage function, and the lParam parameter passed to the ReplacePage member function. lParam Parameter to pass to function specified by lpfnReplacePage. To replace a page, a property sheet handler fills a PROPSHEETPAGE structure, calls CreatePropertySheetPage, and then calls the function specified by IpfnReplacePage. Initialization Interface and Member IShellExtInit Interface used to initialize a property sheet extension, context menu extension, or drag-drop handler. The IShellExtInit interface has the following member functions:
______________________________________
Initialize Initializes the shell extension.
______________________________________
Like all OLE interfaces, IShellExtInit also includes the QueryInterface, AddRef, and Release member functions. IShellExtInit::Initialize
______________________________________
HRESULT STDMETHODCALLTYPE IShellExtInit::Initialize{
LPSHELLEXTINIT pIface, LPCITEMIDLIST pidlFolder,
LPDATAOBJECT lpdobj, HKEY hkeyProgID
};
______________________________________
Initializes a property sheet extension, context menu extension, or drag-drop handler. Returns NOERROR if successful, an OLE-defined error value otherwise. pIface Address of the IShellExtInit interface. In C++, this parameter is implicit. pidlFolder Address of an ITEMIDLIST structure (item identifier list) that uniquely identifies a folder. lpdobj Pointer to an IDataObject interface object that can be used to retrieve the objects being acted upon. hkeyProgID Registry key for the file object or folder type. This is the first member function the shell calls after it creates an instance of a property sheet extension, context menu extension, or drag-drop handler. The meanings of some parameters depend on the extension type. For drag-drop handlers, the item identifier list specifies the destination folder (the drop target); the IDataObject interface identifies the items being dropped; and the registry key specifies the file class of the destination folder. For property sheet extensions and context menu extensions, the item identifier list specifies the folder that contains the selected file objects; the IDataObject interface identifies the selected file objects; and the registry key specifies the file class of the file object that has the focus. Structures CMINVOKECOMMANDINFO
______________________________________
typedef struct .sub.-- CMInvokeCommandInfo {
DWORD cbSize; // sizeof(CMINVOKECOMMANDINFO)
DWORD fMask: // see below
HWND hwnd; // see below
LPCSTR lpVerb; // see below
LPCSTR lpParameters;
// see below
LPCSTR lpDirectory;
// see below
int nShow; // see below
DWORD dwHotKey;
// see below
HANDLE hIcon; // see below
{ CMINVOKECOMMANDINFO, *LPCMINVOKECOMMANDINFO;
______________________________________
Contains information about a context menu command. The address of this structure is passed to the IContextMenu::InvokeCommand member function. fMask Value specifying zero or more of the following flags:
______________________________________
Value Meaning
______________________________________
CMIC.sub.-- MASK.sub.-- HOTKEY
Specifies that the dwHotKey member is
valid.
CMIC.sub.-- MASK.sub.-- ICON
Specifies that the hIcon member is valid.
______________________________________
hwnd Handle of the window that owned the context menu, such as the desktop, the explorer, or the tray. An extension might specify this handle as the owner window of any message boxes or dialog boxes it displays. lpVerb 32-bit value containing zero in the high-order word and the menu-identifier offset of the command to carry out in the low-order word. The shell specifies this value (using the MAKEINTRESOURCE macro) when the user chooses a menu command. If the high order word is not zero, this member is the address of a null-terminated string specifying the language-independent name of the command to carry out. This member is typically a string when a command is being invoked programmatically. lpParameters Optional parameters. This member is always NULL for menu items inserted by a shell extension. lpDirectory Optional working directory name. This member is always NULL for menu items inserted by a shell extension. nShow Flag to pass to the ShowWindow function if the command displays a window or launches an application. dwHotKey Optional hot-key to assign an application launched by the command. Ignore this member if the fMask member does not specify CMIC.sub.-- MASK.sub.-- HOTKEY. hIcon Icon to use for any application launched by the command. Ignore this member if the fMask member does not specify CMIC.sub.-- MASK.sub.-- ICON. ITEMIDLIST
______________________________________
typedef struct .sub.-- ITEMIDLIST ( // idl
SHITEMID mkid; // list of item identifiers
} ITEMIDLIST, * LPITEMIDLIST;
typedef const ITEMIDLIST * LPCITEMIDLIST;
______________________________________
Contains a list of item identifiers. SHITEMID
______________________________________
typedef struct .sub.-- SHITEMID { // mkid
USHORT cb; // size of this identifier, including cb itself
BYTE abID[1];
// variable length item identifier
} SHITEMID, * LPSHITEMID;
typedef const SHITEMID * LPSCHITEMID;
______________________________________
Defines an item identifier. Name-Space Extensions for the Chicago Shell When to Create a Name-Space Extension Chicago's shell allows applications to extend it's functionality with regular shell extensions (icon handlers, context menu handlers, property sheet handlers, drag drop handlers, data object handlers and copy hook handlers), and with Name-Space Extensions. For more information on the regular shell extensions please read the "Extending the Chicago Shell" article. Name-Space Extensions allow applications to expose hierarchical data which may be stored in a file, or anywhere else the Name-Space Extension can access, with the shell's familiar user interface. Files systems, both local and networked, on MS-DOS and Windows NT based systems have hierarchical data. Directories contain files and other directories. End users will use Chicago's shell to access this hierarchical data on a regular basis. If an application has hierarchical data to present to the user, it would reduce training time for the user if the user uses the shell to access this data. A Name-Space Extension extends the shell so that it appears to a user, that the shell understands a hierarchy that is not part of a file system. In Chicago there are some limitations on Name-Space Extensions. Name-Space Extensions should not be used on arbitrary files found in the file system. This means that you should not implement a Name-Space Extension to expose a hierarchy for a file class where files of the class can be found in many places in the file system. For example a Name-Space Extension should not be used to expose the contents of a compressed file, such as a file compressed with PKZIP. Another example would be using a Name-Space Extension to expose the contexts of a spreadsheet or word processing document in the shell. File viewers, and the applications themselves, should be used to do this. To help enforce this limitation, the shell does not provide a way to register a Name-Space Extension for a file class. Registering a Name-Space Extension Name space extensions are tied into the name space 2 ways. One is by adding entries in the registry that place those extensions under the root of the name space "Dekstop" or under "My Computer". File system folders (directories) can be taged as entry points into name space extensions as well. Registring NSEs in the Registry Under "Desktop" or "My Computer" To put an extension under "Desktop" or "My Computer", the handler's CLSID should be registered as a key under either of these two keys. HKEY.sub.-- LOCAL.sub.-- MACHINE/Software/Windows/CurrentVersion/Explorer/Desktop/NameSpace HKEY.sub.-- LOCAL.sub.-- MACHINE/Software/Windows/CurrentVersion/Explorer/MyComputer/NameSpace Under Arbitrary File System Folders There are 2 ways to tag a file system folder (directory) as an entry point into a name-space extension. The first is to put the CLSID of the extension on a directory as a file name extension. This method relies on the file system supporting long filenames. The second is mark a directory with the system or read only bits (ATTRIBUTE.sub.-- READONLY.vertline.ATTRIBUTE.sub.-- SYSTEM), then put a desktop.ini file in that directory that contains the CLSID of the handler. This is less efficient, but works on short name volumes. The two methods are shown below.
__________________________________________________________________________
c:.backslash.window.backslash.NSE (directory marked ATTRIBUTE.sub.--
SYSTEM or ATTRIBUTE.sub.-- READONLY)
c:.backslash.windows.backslash.NSE.backslash.desktop.ini
[.ShellClassInfo]
CLSID={00000000-1111-2222-3333-444444444444}
create a directory that looks like this.
c:.backslash.windows.backslash.NSE.{00000000-1111-2222-3333-444444444444}
__________________________________________________________________________
How the Shell Accesses a Name-Space Extension When the shell sees that a browser has been registered, it performs the following steps: 1. Gets the Clsid of the handler. 2. Creates an IClassFactory object by calling the DllGetClasObject entry of the specified DLL. 3. Calls IClassFactory::CreateInstance with IID.sub.-- IPersistFolder to create its instance. 4. Initializes the instance by calling the IPersistFolder:Initialize method. 5. Uses the QueryInterface method to get to the IShellFolder interface. 6. Calls IShellFolder members as appropriate. The shell displays the first level of the IShellFolder object for the Name-Space Extension, but needs to know how this object should appear. The appearance of the object, both its icon and whether the shell should display a "+" sign on the left of the icon must be described in the registry. For example:
______________________________________
HKEY.sub.-- CLASSES.sub.-- ROOT
CLSID
{00000000-1111-2222-3333-444444444444} = BBS Program
DefaultIcon = bbsdll.dll,0
Hierarchical = 1 // 0:no sub-folder, 1:has sub-folder(s)
______________________________________
If the extension's name-space is hierarchical (i.e., it has one or more sub folders), the explorer calls IShellFolder members to display the sub folders in the explorers left hand pane, it's content pane. To do the this explorer: Calls the EnumObjects method to enumerate the sub folders. Calls the GetDisplaynameOf method to get the names of the sub folders Calls the GetUIObjectOf method to get the icons for the sub folders Calls the GetAttributesOf method to know which sub folders have sub folders of their own. IPersistFolder Interface
__________________________________________________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IPersistFolder, IPersist) // fld
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid, LPVOID FAR* ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG,AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG,Release) (THIS) PURE;
// *** IPersist methods ***
STDMETHOD(GetClassID) (THIS.sub.-- LPCLSID lpClassID) PURE;
// *** IPersistFolder methods ***
STDMETHOD(Initialize) (THIS.sub.--
LPCITEMIDLIST pidl) PURE;
};
__________________________________________________________________________
IDLists OLE 2.0 introduced objects call monikers, which were used to identify and bind references to link sources to the code for reconnection. The Chicago shell provides a similar object called an ItemID. ItemIDs are variable-length byte streams that contain information for identifying a file object within a folder. An ItemID does not contain non-persistent values such as pointers to data structures, window handles, or atoms. This is because the shell may store ItemIDs in persistent storage (that is, on disk) and use them later. An ItemID is defined as follows:
______________________________________
typedef struct .sub.-- SHITEMID
USHORT cb; // Size of the ItemID
BYE abID[1];
// This ItemID (variable length)
} SHITEMID, FAR* LPSHITEMID;
typedef const SHITEMID FAR * LPCSHITEMID;
______________________________________
ItemIDs may also contain information that helps improve the efficiency with which you can manipulate the file object, for example, the file object's display name or sorting information. The shell does not need to know the actual content of an ItemID. The only part of an ItemID the shell uses is the first two bytes, which contain the size of the ItemID. The shell does not look at the rest of the ItemID directly; this information is usable only by the handler that created the ItemID. The shell often concatenates ItemIDs and adds a NULL terminator at the end, creating an IDList. An IDList that contains only one ItemID is called a simple IDList, and an IDList that contains multiple ItemIDs is called a complex IDList. For consistency, the shell always passes a pointer to an IDList even when the receiving handler can only use a single ItemID. IDLists are defined as follows:
______________________________________
typedef struct .sub.-- ITEMIDLIST // idl
SHITEMID mkid;
} ITEMIDLIST, FAR* LPITEMIDLIST;
typedef const ITEMIDLIST FAR* LPCITEMIDLIST;
______________________________________
The shell always converts any monikers it receives, for example from the EnumObjects member of an IShellFolder interface, to ItemIDs by calling the interface's IDListFromMoniker member. In addition to the information to identify a file object, an ITEMID may contain more information that can enhance the efficiency of manipulating the file object. For example the file objects display name or sorting information. Since the shell knows how to handle ITEMIDs efficiently, shell extensions should return ITEMIDs when someone is enumerating though the handlers objects with the IEnumUnknown::Next() method. IDMoniker related functions HRESULT WINAPI SHCreateIDMoniker(LPCITEMIDLIST pidl, LPMONIKER FAR* ppmk); HRESULT SHGetIDFromIDMoniker(LPMONIKER pmk, IPITEMIDLIST FAR* ppidl); IDList related functions BOOL WINAPI SHGetPathFromIDList(LPCITEMIDLIST pidl, LPSTR pszPath); Shell Folder The IShellFolder interface is derived from OLE's IOleContainer interface. The IOleContainer interface is used to enumerate objects in a container. Similarly the IShellFolder interface is used to enumerate objects within a file object. IShellFolder provides name parsing and enumeration of objects, that is, an outside-in view of the objects within a file object. IOleContainer is itself derived from the IParseDisplayName interface.
__________________________________________________________________________
DECLARE.sub.-- INTERFACE.sub.-- (IShellFolder, IOleContainer)
// *** IUnknown methods ***
STDMETHOD(QueryInterface) (THIS.sub.-- REFIID riid, LPVOID FAR* ppvObj)
PURE;
STDMETHOD.sub.-- (ULONG,AddRef) (THIS) PURE;
STDMETHOD.sub.-- (ULONG,Release) (THIS) PURE;
// *** IParseDisplayName method ***
STDMETHOD(ParseDisplayName) (THIS.sub.-- LPBC pbc, LPOLESTR
lpszDisplayName,
ULONG FAR* pchEaten, LPMONIKER FAR* ppmkOut) PURE;
// *** IOleContainer methods ***
STDMETHOD(EnumObjects) ( THIS.sub.-- DWORD grfFlags,
LPENUMUNKNOWN FAR* ppenumUnknown) PURE;
STDMETHOD(LockContainer) (THIS.sub.-- BOOL fLock) PURE;
// *** IShellFolder methods ***
STDMETHOD(BindToObject)
(THIS.sub.-- LPCITEMIDLIST pidl, LPBC pbc,
REFIID riid, LPVOID FAR* ppvOut) PURE;
STDMETHOD(BindToStorage)
(THIS.sub.-- LPCITEMIDLIST pidl, LPBC pbc,
REFIID riid, LPVOID FAR* ppvObj) PURE;
STDMETHOD(CompareIDs)
(THIS.sub.-- LPARAM lParam,
LPCITEMIDLIST pidll, LPCITEMIDLIST pidl2) PURE;
STDMETHOD(CreateViewObject)
(THIS.sub.-- HWND hwndOwner, REFIID riid,
LPVOID FAR* ppvOut) PURE;
STDMETHOD(GetAttributesOf)
(THIS.sub.-- UINT cidl, LPCITEMIDLIST FAR* apidl,
ULONG FAR* rgfInOut) PURE;
STDMETHOD(GetUIObjectOf)
(THIS.sub.-- HWND hwndOwner, UINT cidl,
LPCITEMIDLIST FAR* apidl,
REFIID riid, UINT FAR* prgfInOut, LPVOID FAR* ppvOut) PURE;
STDMETHOD(GetDisplayNameOf)
(THIS.sub.-- LPCITEMIDLIST pidl, DWORD uFlags,
LPSTRRET lpName) PURE;
STDMETHOD(SetNameOf)
(THIS.sub.-- HWND hwndOwner, LPCITEMIDLIST pidl,
LPCOLESTR lpszName, DWORD uFlags,
LPITEMIDLIST FAR* ppidlOut) PURE;
STDMETHOD(MonikerToIDList)
(THIS.sub.-- LPMONIKER pmk,
LPITEMIDLIST FAR* pidl) PURE;
};
__________________________________________________________________________
IShellFolder EnumObjects The IOleContainer interface defines a method, EnumObjects, which returns a flag. The shell defines these flags for this method to use:
______________________________________
typedef enum tagSHCONTF
SHCONTF.sub.-- FOLDERS
= 32, // for shell browser
SHCONTF.sub.-- NONFOLDERS
= 64, // for default view
SHCONTF.sub.-- INCLUDEHIDDEN
= 128 , // for hidden/system objects
} SHCONTF;
______________________________________
Unique IShellFolder Methods This interface implements the followings method in addition to the IParseDisplayName and IOleContainer methods. BindToObject This function returns an instance of a sub-folder which is specified by the IDList (pidl). Syntax BindToObject(LPCITEMIDLIST pidl, LPBC pbc, REFIID riid, LPVOID FAR* ppvOut) Parameters
______________________________________
pidl Pointer to an ItemID list.
pbc Points to the bind context, an instance of the IBindCtx interface,
to be used for this binding operation.
riid Identifies the interface by which the caller wants to connect to
the object.
ppvOut
On a successful return, points to the instantiated object unless
BINDFLAGS.sub.-- JUSTTESTEXISTENCE was specified in the
binding options. If BINDFLAGS.sub.-- JUSTTESTEXISTENCE was
specified, NULL can be returned instead.
______________________________________
EXAMPLE | ||||||
