Registering Shell Extension Handlers

最近在做Windows shell extension 的开发工作,对shell extension handler的注册机制有点疑问,以下摘自MSDN:http://msdn.microsoft.com/en-us/library/windows/desktop/cc144067(v=vs.85).aspx

Registering Shell Extension Handlers

A Shell extension handler object must be registered before the Shell can use it. This section is a general discussion of how to register a Shell extension handler.

Any time you create or change a Shell extension handler, it is important to notify the system that you have made a change with SHChangeNotify, specifying the SHCNE_ASSOCCHANGED event. If you do not call SHChangeNotify, the change might not be recognized until the system is rebooted.

As with all COM objects, you must create a GUID for the handler using a tool such as UUIDGEN.exe. Create a key under HKEY_CLASSES_ROOT\CLSID whose name is the string form of the GUID. Because Shell extension handlers are in-process servers, you must create an InProcServer32 key under the GUID key with the default value set to the path of the handler's DLL. Use the Apartment threading model.

Any time the Shell takes an action that can involve a Shell extension handler, it checks the appropriate registry key. The key under which an extension handler is registered thus controls when it will be called. For instance, it is a common practice to have a shortcut menu handler called when the Shell displays a shortcut menu for a member of a file type. In this case, the handler must be registered under the file type's ProgID key.

Handler Names

To enable a Shell extension handler, create a subkey with the handler subkey name (see below) under the ShellEx subkey of either the ProgID (for file types) or the Shell object type name (for Predefined Shell Objects).

For example, if you wanted to register a shortcut menu extension handler for MyProgram.1, you would begin by creating the following subkey:

 

HKEY_CLASSES_ROOT
   MyProgram.1
      ShellEx
         ContextMenuHandlers

For the following handlers, create a subkey underneath the "Handler Subkey name" key whose name is the string version of the CLSID of the Shell extension. Multiple extensions can be registered under the handler subkey name key by creating multiple subkeys.

HandlerInterfaceHandler Subkey Name
Shortcut menu handlerIContextMenuContextMenuHandlers
Copyhook handlerICopyHookCopyHookHandlers
Drag-and-drop handlerIContextMenuDragDropHandlers
Property sheet handlerIShellPropSheetExtPropertySheetHandlers
Column provider handler (deprecated in Windows Vista)IColumnProviderColumnHandlers

 

For the following handlers, the default value of the "Handler Subkey Name" key is the string version of the CLSID of the Shell extension. Only one extension can be registered for these handlers.

HandlerInterfaceHandler Subkey Name
Data handlerIDataObjectDataHandler
Drop handlerIDropTargetDropHandler
Icon handlerIExtractIconA/WIconHandler
Image handlerIExtractImage{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}
Thumbnail image handlerIThumbnailProvider{E357FCCD-A995-4576-B01F-234630154E96}
Infotip handlerIQueryInfo{00021500-0000-0000-C000-000000000046}
Shell link (ANSI )IShellLinkA{000214EE-0000-0000-C000-000000000046}
Shell link (UNICODE)IShellLinkW{000214F9-0000-0000-C000-000000000046}
Structured storageIStorage{0000000B-0000-0000-C000-000000000046}
MetadataIPropertyStorePropertyHandler
MetadataIPropertySetStorage (deprecated in Windows Vista)PropertyHandler
Pin to Start MenuIStartMenuPinnedList{a2a9545d-a0c2-42b4-9708-a0b2badd77c8}
Pin to Taskbar {90AA3A4E-1CBA-4233-B8BB-535773D48449}

 

The subkeys specified to add Pin to Start Menu and Pin to Taskbar to an item's shortcut menu are only required for file types that include the IsShortCut entry.

Support for column provider handlers was removed in Windows Vista. Also, as of Windows Vista,IPropertySetStorage has been deprecated in favor of IPropertyStore.

While IExtractImage remains supported, IThumbnailProvider is preferred for Windows Vista and later.

Predefined Shell Objects

The Shell defines additional objects under HKEY_CLASSES_ROOT which can be extended in the same way as file types. For example, to add a property sheet handler for all files, you can register under thePropertySheetHandlers key.

 

HKEY_CLASSES_ROOT
   *
      shellex
         PropertySheetHandlers

The following table gives the various subkeys of HKEY_CLASSES_ROOT under which extension handlers can be registered. Note that many extension handlers cannot be registered under all of the listed subkeys. For further details, see the specific handler's documentation.

SubkeyDescriptionPossible HandlersVersion
*All filesShortcut Menu, Property Sheet, Verbs (see below)All
AllFileSystemObjectsAll files and file foldersShortcut Menu, Property Sheet, Verbs4.71
FolderAll foldersShortcut Menu, Property Sheet, VerbsAll
DirectoryFile foldersShortcut Menu, Property Sheet, VerbsAll
Directory\BackgroundFile folder backgroundShortcut Menu only4.71
DriveAll drives in MyComputer, such as "C:\"Shortcut Menu, Property Sheet, VerbsAll
NetworkEntire network (under My Network Places)Shortcut Menu, Property Sheet, VerbsAll
Network\Type\#All objects of type # (see below)Shortcut menu, Property Sheet, Verbs4.71
NetShareAll network sharesShortcut menu, Property Sheet, Verbs4.71
NetServerAll network serversShortcut menu, Property Sheet, Verbs4.71
network_provider_nameAll objects provided by network provider "network_provider_name"Shortcut menu, Property Sheet, VerbsAll
PrintersAll printersShortcut Menu, Property SheetAll
AudioCDAudio CD in CD driveVerbs onlyAll
DVDDVD drive (Windows 2000)Shortcut Menu, Property Sheet, Verbs4.71

 

Notes:

  • The file folder background shortcut menu is accessed by right-clicking within a file folder, but not over any of the folder's contents.
  • "Verbs" are special commands registered under HKEY_CLASSES_ROOT\Subkey\Shell\Verb .
  • For Network\Type\# , "#" is a network provider type code in decimal. The network provider type code is the high word of a network type. The list of network types is given in the Winnetwk.h header file (WNNC_NET_* values). For example, WNNC_NET_SHIVA is 0x00330000, so the corresponding type key would be HKEY_CLASSES_ROOT\Network\Type\51 .
  • "network_provider_name" is a network provider name as specified by WNetGetProviderName, with the spaces converted into underscores. For example, if the Microsoft Networking network provider is installed, its provider name is "Microsoft Windows Network", and the correspondingnetwork_provider_name is Microsoft_Windows_Network.

Example of an Extension Handler Registration

To enable a particular handler, create a subkey under the extension handler type key with the name of the handler. The Shell does not use the handler's name, but it must be different from all other names under that type subkey. Set the default value of the name subkey to the string form of the handler's GUID.

The following example illustrates registry entries that enable shortcut menu and property sheet extension handlers, using an example .myp file type:

 

HKEY_CLASSES_ROOT
   .myp
      (Default) = MyProgram.1
   CLSID
      {00000000-1111-2222-3333-444444444444}
         InProcServer32
            (Default) = C:\MyDir\MyCommand.dll
            ThreadingModel = Apartment
      {11111111-2222-3333-4444-555555555555}
         InProcServer32
            (Default) = C:\MyDir\MyPropSheet.dll
            ThreadingModel = Apartment
   MyProgram.1
      (Default) = MyProgram Application
      Shellex
         ContextMenuHandler
            MyCommand
               (Default) = {00000000-1111-2222-3333-444444444444}
         PropertySheetHandlers
            MyPropSheet
               (Default) = {11111111-2222-3333-4444-555555555555}

The registration procedure discussed in this section must be followed for all Windows systems.

转载于:https://www.cnblogs.com/gomen/p/3437301.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值