OLE Drag and Drop

Besides the clipboard, OLE also provides another means of getting an IDataObject pointer from a source to a consumer: OLE Drag and Drop. Because you can exchange virtually any data through a data object, you can exchange virtually any data through this very direct and user-oriented mechanism, which is widely exploited in the Windows 95 shell.

Drag and Drop effectively streamlines whatever you might do with the clipboard. With the clipboard, the user must select the data, choose Cut or Copy from the source menu, switch applications, mark the insertion point, and choose Paste from the consumer menu. With OLE Drag and Drop, the user selects the data, picks it up by holding down the mouse button, drags it to the insertion point in the consumer (called the target in this context), and then releases the mouse button to drop it in the target. OLE performs a Move (Cut) operation by default, which the user can modify to a Copy operation by holding down the Ctrl key or a Link operation by holding down Shift+Ctrl (assuming the source provides a moniker in the data object).

During the process, the source controls the mouse cursor and determines when a drop happens (because it knows what caused the drag), when the operation should be canceled (Esc is pressed), or when the operation should continue. The source accomplishes this through an interface named IDropSource. The target, on the other hand, associates an implementation of IDropTarget with a visible window (such as a document), with that interface being told when the mouse cursor moves in, around, or out of the window and when a drop happens. All this time, the target communicates to the source the "effect" (move, copy, link) that would happen if a drop occurred, and the source uses this information to set the mouse cursor to an appropriate image. The target usually also draws something in its own window to indicate the insertion point of the data, such as a caret or a dotted rectangle. Furthermore, the target also provides the user with the ability to scroll through the target window during the operation by holding the mouse cursor inside the window's border for a short period of time.

All of these considerations, not only for the target but also for the source, are topics for Chapter 13. There we'll see that OLE Drag and Drop is a tremendous user benefit, and if you implement a data object for the clipboard first, your drag-and-drop implementation is close to trivial.