treedroptarget.h

Go to the documentation of this file.
00001 /**************************************************************************
00002    THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF
00003    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00004    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00005    PARTICULAR PURPOSE.
00006    Author: Leon Finker  01/2001
00007    Modifications: removed ATL dependencies, Martin Fuchs 7/2003
00008 **************************************************************************/
00009 
00010 #include "dragdropimpl.h"
00011 
00012  /// OLE drop target for tree controls
00013 class TreeDropTarget : public IDropTargetImpl
00014 {
00015 public:
00016     TreeDropTarget(HWND hTargetWnd) : IDropTargetImpl(hTargetWnd) {}
00017 
00018     virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD *pdwEffect)
00019     {
00020         if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
00021         {
00022             HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
00023             if (hDrop != NULL)
00024             {
00025                 TCHAR szFileName[MAX_PATH];
00026 
00027                 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
00028 
00029                 for(UINT i = 0; i < cFiles; ++i)
00030                 {
00031                     DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
00032 
00033                     if (DROPEFFECT_COPY & *pdwEffect)
00034                     {
00035                          // copy the file or dir
00036 
00037                         ///@todo Add the code to handle Copy
00038 
00039                     }
00040                     else if (DROPEFFECT_MOVE & *pdwEffect)
00041                     {
00042                          // move the file or dir
00043 
00044                         ///@todo Add the code to handle Move
00045 
00046                     }
00047                 }
00048                 //DragFinish(hDrop); // base class calls ReleaseStgMedium
00049             }
00050             GlobalUnlock(medium.hGlobal);
00051         }
00052 
00053         TreeView_SelectDropTarget(m_hTargetWnd, NULL);
00054 
00055         return true; //let base free the medium
00056     }
00057 
00058     virtual HRESULT STDMETHODCALLTYPE DragOver(
00059         /* [in] */ DWORD grfKeyState,
00060         /* [in] */ POINTL pt,
00061         /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
00062     {
00063         TVHITTESTINFO hit;
00064         hit.pt = (POINT&)pt;
00065         ScreenToClient(m_hTargetWnd, &hit.pt);
00066         hit.flags = TVHT_ONITEM;
00067         HTREEITEM hItem = TreeView_HitTest(m_hTargetWnd,&hit);
00068 
00069         if (hItem != NULL)
00070             TreeView_SelectDropTarget(m_hTargetWnd, hItem);
00071 
00072         return IDropTargetImpl::DragOver(grfKeyState, pt, pdwEffect);
00073     }
00074 
00075     virtual HRESULT STDMETHODCALLTYPE DragLeave(void)
00076     {
00077         TreeView_SelectDropTarget(m_hTargetWnd, NULL);
00078 
00079         return IDropTargetImpl::DragLeave();
00080     }
00081 };

ROS Explorer Source Code Documentation
generated on 02.01.2013 by doxygen

ROS Explorer Homepage