Answer:
There is an excellent resource on the web on OLE drag and drop. See the full article at http://www.wideman-one.com/gw/tech/Delphi/dragdrop/DragDrop_OverView.htm
Orientation
There are plenty of reasons for you to want your application to be able to accept
drops from other applications. Often you may just want to accept or source a file
or files, but at other times you want to be able to accept or source other items, and
here's where the fun starts. If you've looked into how to do that, you'll have run
into the steep learning curve associated with getting into Microsoft's COM/OLE system.
Well, thankfully, a number of authors have recently tackled that topic, and laid down
most of the path for us to follow. To really nail down the concepts, and see how OLE
drag-and-drop works, I decided to build some demo apps that would:
- Demonstrate and clarify:
- how an application prepares participate in OLE drag-and-drop
- how to clean up at the end
- several loose ends left by the references that I consulted.
- Provide Browsing capability:
- view the data formats that other source apps offer to drop.
- the actual data content for each format.
Version applicability: This article applies to (and the software has
been tested with) Windows NT 4 (SP3) and Windows 95. It uses techniques that have applied
certainly since 1995, hence should work with NT 3.5x, and who knows, might even work with
NT 5 and Windows 98!. The code is for Delphi 3, I expect it to work in Delphi 4, and it
may also work with Delphi 2.
Drag and Drop Variations
There are at least three different drag-and-drop variations to think about:
Within-app drag-and-drop: Your app manages this any way you like,
using the various drag and drop events provided with Delphi TControls. Since you have
control over both ends of the transaction, you can move any kind of data you like.
You could use COM in the process, but you certainly don't have to.
Between-app drag-and-drop: The source and destination applications
must each provide certain COM objects to manage the drag-time behavior, and to pass the
data from one app to the other. If you try to read the "raw" OLE
documentation on how to do this, it looks daunting. Fear not, Delphi makes it
somewhat easier, and the third-party books, demos, and the demo I describe here show the
way.
Between-app drag-and-drop, Files Only: So-called CF_HDROP
(clipboard-format, handle for dropping files). Accepting dropped files is a limited but
often-useful subset of general drop-accept capability, so Windows provides a way to do
this without requiring your app to know about COM. Jim Mischel covers this in
"High Performance Delphi 3"... but later concludes (and it looks about right to
me) "What I found most surprising about [the OLE] drop target implementation is that
it's less complicated than the [files-only implementation]".
Pieces to Master
There are two main things to master:
- How to work with COM objects. For more info on this subject
visit the "Understanding COM (OLE)..." reference in the Contents.
- Understand the Sequence of Events in Drag and Drop: OLE Drag and Drop
involves what at first seems a relatively complicated series of interactions between
several COM objects, some on the source app side, and some on the target app side, several
of which are rather confusingly named. It actually turns out that the mechanism is a
pretty straightforward conversation, but you really need a diagram to follow it. I decided
to sketch one out in the form of a UML-style sequence diagram.
With that said, proceed to try out the demo applications, or go to the Theory page...
see Contents page.
Resources/References
- Taylor, Mischel, Penman, Goggin, Shemitz: "High Performance Delphi 3
Programming" 1998
- Cantu, Gooch, Lam: "Delphi Developer's Handbook" 1998
- Brockschmidt: "Inside OLE 2" (first and second editions) 1994, 1995?
|