Since I don't know where to put the source, I only talk about my thinking.
Use the clipboard to register a clipboard file type.
RegisterClipboardFormat (LPCTSTR LPSZFORMAT);
Register a custom clipboard format that can be dragged and dropped any data.
Let's introduce the implementation of drag and drop:
To make the control support to drag and drop, you must first implement a class, inherit it in the COLLDROPTARGET. And then
Reload several functions of the ColedropTarget.
virtual DROPEFFECT OnDragEnter (CWnd * pWnd, COleDataObject * pDataObject, DWORD dwKeyState, CPoint point); virtual DROPEFFECT OnDragOver (CWnd * pWnd, COleDataObject * pDataObject, DWORD dwKeyState, CPoint point); virtual void OnDragLeave (CWnd * pWnd); virtual BOOL OnDrop (CWND * PWND, COLEDATAOBJECT * PDATAOBJECT, DROPEFFECT DROPEFFECT, CPOINT POINT; then register this class for the target object to be dragged and dropped.
m_droptarget.register (this);
When the source object starts to drag, create a COLEDATASOSOURCE object and drag and drop
The data is placed inside.
COleDataSource * poleSourceObj = new COleDataSource; HGLOBAL hData = GlobalAlloc (GHND | GMEM_SHARE, str.GetLength () 1); strcpy ((LPSTR) GlobalLock (hData), str.LockBuffer ()); GlobalUnlock (hData); poleSourceObj-> CacheglobalData; DROPEFFECT DROPEFFECT = POLESOURCEOBJ-> DODRAGDROP (); if (DROPEFFECT == DROPEFFECT_MOVE) deleteItem (HTSELITEM); Delete PolesourceObj;
Ondrop () function in our heavy load
Virtual Bool OnDrop (CWND * PWND, COLEDATAOBJECT * PDATAOBJECT, DROPEFFECT DROPEFFECT, CPOINT POINT), and the data is extracted.
Hglobal hdata = pDataObject-> getGlobalData (cf_text); cstring stratxt = (lptstr) Globalock (HDATA);
This will achieve drag and drop. .