Chapter 7. Drop Handlers

Drop handlers allow file objects to become drop targets—that is, to define a custom behavior when one or more files are dropped on them. When a file is dropped on another file, the handler is provided with the names of both the target and source file(s). The files can then be processed in any manner appropriate to the situation. Consider the popular WinZip archive program. When a file is dropped onto an existing .zip file, it is added to the archive. This behavior is accomplished with the help of a drop handler.

Drop handlers are easy to implement. They implement two interfaces (IDropTarget and IPersistFile), one of which is already familiar to us.

The drop handler we will implement in this chapter offers no practical functionality other than to show you how one works. It will allow you to drop one or more files onto a .rad file object. The drop handler will report the names of the source file(s), the target file, and keyboard/mouse states.

How Drop Handlers Work

When one file (the source file) is dragged over another file (the target file), the shell checks under the target file’s application identifier key to see if a drop handler has been registered for that particular file class. This key is in the following location (assuming we are talking about .rad files):

HKEY_CLASSES_ROOT\
    radfile\
        shellex\
            DropHandler = {CLSID}

Tip

As you can see from the registry setting, there can be only one drop handler registered for a file class.

If a drop handler for the target ...

Get VB Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.