Serializing ASCII Data
Modeless child dialog
Modeless sibling dialog
The drag source
The MFC drop target
The TBTextTarget class
VC6 flat toolbar support
Doing it the OLE way... an interface class to derive from
If you are a MFC purist and only want to have CObject derived classes in your project,
than consider the pure MFC drop target.
You find the sample
project in step3generic or you may download only the TBTextTarget
A generic IDropTarget COM class for dropped texts
I promised you "a better way" and I fulfill this promise now
- at least half of it because its for the drop target, the IDropSouce
and IDataObject parts are missing, but the MFC support for the begin of
dragging out of CListCtrl is quite good (perhaps someone else can take
this as an excersice and I'll puplish her/his work as an addendum of this
The OLE docs say: "If you want your (window) class to be drop-enabled,
implement a IDropTarget interface." Nice - eh' what did it say? In
plain English Id say: your drop-enabled class needs a couple of
functions which do the right things. The bundle of these functions make
out "the interface" and because some interfaces are "at
the top" of others you have - a kind of class hierarchy!
Due to the fact that we are talking about text dragging the private data
format described in the other articles of this series is just omitted,
but might easily . Implement the drag sources as common interface (CF_TEXT,
see "Data is going abroad..." for the drop part do the following
(and compare with the pure MFC stuff!)
- Create your CWnd-based class (CYourClass, e.g. your dialog) as usual.
- include the files TBTextTarget.h and TBTextTarget.cpp in your project.
- Go to the class definition of CYourClass and derive it from TBTextTarget
too: e.g. the line
CDropDialog : public CDialog
: public CDialog, TBTextTarget
- Dont forget to #include "TBTextTarget.h"
- Don't forget to make a call to AfxOleInit()
in your applications InitInstance function before creating any
windows or document templates.
- At a point where this window is created (for example: OnInitDialog
is great), tell Windows that you are drag&drop-enabled:
// the other stuff follows ....
- Add this function to CYourClass (its pure virtual in TBTextTarget
because it depents on YOU what you do with YOUR data):
void ProcessData(CString Data)
This function will be called when a text
was dragged into your window. Do with it what ever you like (or need).
CString t1(Data), t2;
int idx = t1.Find('\n');
while (idx !=-1)
t2 = t1.Left(idx);
t1 = t1.Mid(idx+1);
idx = t1.Find('\n');