Upravit

Sdílet prostřednictvím


How to Create Drop Handlers

By default, files are not drop targets. You can make the members of a file type into drop targets by implementing and registering a drop handler.

If a drop handler is registered for a file type, it is called whenever an object is dragged over or dropped on a member of the file type. The Shell manages the operation by calling the appropriate methods on the handler's IDropTarget interface.

The general procedures for implementing and registering a Shell extension handler are discussed in Creating Shell Extension Handlers. This document focuses on those aspects of implementation that are specific to drop handlers.

Instructions

Step 1: Implementing Drop Handlers

Like all Shell extension handlers, drop handlers are in-process Component Object Model (COM) objects implemented as DLLs. They export two interfaces in addition to IUnknown: IPersistFile and IDropTarget.

The Shell initializes the handler through its IPersistFile interface. It uses this interface to request the handler's class identifier (CLSID) and provides it with the file's name. For a general discussion of how to implement Shell extension handlers, including the IPersistFile interface, see Creating Shell Extension Handlers.

Once the drop handler is initialized, the Shell calls the appropriate method on the handler's IDropTarget interface.

Step 2: Registering Drop Handlers

Drop handlers are registered under this file type's subkey.

HKEY_CLASSES_ROOT
   ProgID
      shellex
         DropHandler

Create a subkey of DropHandler named for the handler, and set the subkey's default value to the string form of the handler's CLSID GUID. For a general discussion of how to register Shell extension handlers, see Creating Shell Extension Handlers.

The following example illustrates registry entries that enable a drop handler for 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
   MyProgram.1
      (Default) = MyProgram Application
      shellex
         DropHandler
            (Default) = {00000000-1111-2222-3333-444444444444}

Creating Shell Extension Handlers

IDropTarget

IPersistFile