ReactOS  0.4.15-dev-1068-g467feb9
CSendToZip.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Zip Shell Extension
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: SendTo handler
5  * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6  * Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 
9 #include "precomp.h"
10 
13  DWORD *pdwEffect)
14 {
15  m_pDataObject = pDataObj;
16 
17  FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
18  m_fCanDragDrop = SUCCEEDED(pDataObj->QueryGetData(&etc));
19 
20  if (m_fCanDragDrop)
21  *pdwEffect &= DROPEFFECT_COPY;
22  else
23  *pdwEffect = DROPEFFECT_NONE;
24 
25  return S_OK;
26 }
27 
29 {
30  if (m_fCanDragDrop)
31  *pdwEffect &= DROPEFFECT_COPY;
32  else
33  *pdwEffect = DROPEFFECT_NONE;
34 
35  return S_OK;
36 }
37 
39 {
42  return S_OK;
43 }
44 
46 CSendToZip::Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt,
47  DWORD *pdwEffect)
48 {
49  m_pDataObject = pDataObj;
50 
51  if (!pDataObj || !m_fCanDragDrop)
52  {
53  DPRINT1("Drop failed: %d %d\n", !pDataObj, !m_fCanDragDrop);
54  *pdwEffect = 0;
55  DragLeave();
56  return E_FAIL;
57  }
58 
59  STGMEDIUM stg;
60  FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
61  HRESULT hr = pDataObj->GetData(&etc, &stg);
63  {
64  *pdwEffect = 0;
65  DragLeave();
66  return E_FAIL;
67  }
68 
69  HDROP hDrop = reinterpret_cast<HDROP>(stg.hGlobal);
70  UINT cItems = ::DragQueryFileW(hDrop, -1, NULL, 0);
71 
72  CZipCreator *pCreator = CZipCreator::DoCreate();
73 
74  for (UINT iItem = 0; iItem < cItems; ++iItem)
75  {
77  DragQueryFileW(hDrop, iItem, szPath, _countof(szPath));
78 
79  pCreator->DoAddItem(szPath);
80  }
81 
82  ::ReleaseStgMedium(&stg);
83 
84  CZipCreator::runThread(pCreator); // pCreator is deleted in runThread
85 
86  DragLeave();
87  return hr;
88 }
STDMETHODIMP DragEnter(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
Definition: CSendToZip.cpp:12
HRESULT hr
Definition: shlfolder.c:183
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
#define pt(x, y)
Definition: drawing.c:79
BOOL m_fCanDragDrop
Definition: CSendToZip.hpp:19
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
static CZipCreator * DoCreate()
Definition: CZipCreator.hpp:20
#define E_FAIL
Definition: ddrawi.h:102
virtual void DoAddItem(LPCWSTR pszFile)
const DWORD DROPEFFECT_COPY
Definition: oleidl.idl:930
const DWORD DROPEFFECT_NONE
Definition: oleidl.idl:929
#define FALSE
Definition: types.h:117
#define STDMETHODIMP
Definition: basetyps.h:43
smooth NULL
Definition: ftsmooth.c:416
STDMETHODIMP Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
Definition: CSendToZip.cpp:46
#define CF_HDROP
Definition: constants.h:410
static BOOL runThread(CZipCreator *pCreator)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
STDMETHODIMP DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
Definition: CSendToZip.cpp:28
#define S_OK
Definition: intsafe.h:51
LPCWSTR szPath
Definition: env.c:35
void Release()
Definition: atlcomcli.h:140
HRESULT QueryGetData([in, unique] FORMATETC *pformatetc)
STDMETHODIMP DragLeave()
Definition: CSendToZip.cpp:38
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
CComPtr< IDataObject > m_pDataObject
Definition: CSendToZip.hpp:18
UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength)
Definition: shellole.c:627
#define SUCCEEDED(hr)
Definition: intsafe.h:49