1 /************************************************************************** 2 THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF 3 ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 4 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 5 PARTICULAR PURPOSE. 6 Author: Leon Finker 01/2001 7 Modifications: removed ATL dependencies, Martin Fuchs 7/2003 8 **************************************************************************/ 9 10 #include "dragdropimpl.h" 11 12 /// OLE drop target for tree controls 13 class TreeDropTarget : public IDropTargetImpl 14 { 15 public: 16 TreeDropTarget(HWND hTargetWnd) : IDropTargetImpl(hTargetWnd) {} 17 18 virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD *pdwEffect) 19 { 20 if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL) 21 { 22 HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal); 23 if (hDrop != NULL) 24 { 25 TCHAR szFileName[MAX_PATH]; 26 27 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); 28 29 for(UINT i = 0; i < cFiles; ++i) 30 { 31 DragQueryFile(hDrop, i, szFileName, sizeof(szFileName)); 32 33 if (DROPEFFECT_COPY & *pdwEffect) 34 { 35 // copy the file or dir 36 37 ///@todo Add the code to handle Copy 38 39 } 40 else if (DROPEFFECT_MOVE & *pdwEffect) 41 { 42 // move the file or dir 43 44 ///@todo Add the code to handle Move 45 46 } 47 } 48 //DragFinish(hDrop); // base class calls ReleaseStgMedium 49 } 50 GlobalUnlock(medium.hGlobal); 51 } 52 53 TreeView_SelectDropTarget(m_hTargetWnd, NULL); 54 55 return true; //let base free the medium 56 } 57 58 virtual HRESULT STDMETHODCALLTYPE DragOver( 59 /* [in] */ DWORD grfKeyState, 60 /* [in] */ POINTL pt, 61 /* [out][in] */ DWORD __RPC_FAR *pdwEffect) 62 { 63 TVHITTESTINFO hit; 64 hit.pt.x = pt.x; 65 hit.pt.y = pt.y; 66 ScreenToClient(m_hTargetWnd, &hit.pt); 67 hit.flags = TVHT_ONITEM; 68 HTREEITEM hItem = TreeView_HitTest(m_hTargetWnd,&hit); 69 70 if (hItem != NULL) 71 TreeView_SelectDropTarget(m_hTargetWnd, hItem); 72 73 return IDropTargetImpl::DragOver(grfKeyState, pt, pdwEffect); 74 } 75 76 virtual HRESULT STDMETHODCALLTYPE DragLeave(void) 77 { 78 TreeView_SelectDropTarget(m_hTargetWnd, NULL); 79 80 return IDropTargetImpl::DragLeave(); 81 } 82 }; 83