I have written a control derived from CWnd and I'm trying to implement drag and drop between two instances of it.
I have tried adding a COleDropTarget derived member variable and calling member.Register(this) in the control's OnCreate handler. For some reason the Register function returns 0 (failure) and the overidden OnDrag functions don't get called!
Any ideas? According to the documentation, I can use a COleDropTarget in a non-CView derived class. Why is failing? What must I do?
Ignore that question - I figured it out - It was the AfxOleInit that was missing.
One more question...
How do you implement the COleDataSource part.
My data will be a text string for now - Max length about 250-500 characters.
I only need CF_TEXT format to start, but I'd like to know how to use my own data format too.
I don't understand why you need to implement COleDropSource class. It wraps IDropInterface that allows you get feedback during drag and drop operation. You need to declare on stack where you want to implement drag and drop COleDataObject class instance. Then you need to create data object. Allocate memory block large enogh for your text data with GlobalAlloc. Lock it with GlobalLock. Copy text to allocated memory. Then call COleDataObject::CachGlobalData passing handle to global memro you allocated and locked. Next step is call to COleDataObject::DoDragDrop. Last default parameter is pointer to COleDropSource class. you can derive you own class from COleDropSource and override its virtual functions which will be called during drag and drop. DoDragDrop enters modal loop until drop occurs or drag and drop operation is cancelled.
Finally you need to unlock and free memory with GlobalUnlock and GlobalFree. If you want to use your own format you need first to register it with COleDataObject::RegisterClipboardFormat
0
richweedAuthor Commented:
Galkin
I'm not using a text string anymore, but my FVInfo data structure instead. (IMAGEBARINFO FVInfo)
Is this code correct?
Yes, you allocate global memory with GlobalAlloc for your structure, lock it with GlobalLock. given a pointer to allocated memory you copy your structure. Then you register custom clipboard format with RegisterClipboardFormat. After that you call CacheGlobalData and DoDragDrop.
0
The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!
Finally you need to unlock and free memory with GlobalUnlock and GlobalFree. If you want to use your own format you need first to register it with COleDataObject::RegisterCl