-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "DropTarget.h" | ||
#include "MultiReplacePanel.h" | ||
|
||
DropTarget::DropTarget(HWND hwnd, MultiReplace* parent) | ||
: _refCount(1), _hwnd(hwnd), _parent(parent) {} | ||
|
||
HRESULT DropTarget::DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) { | ||
UNREFERENCED_PARAMETER(pDataObj); | ||
UNREFERENCED_PARAMETER(grfKeyState); | ||
UNREFERENCED_PARAMETER(pt); | ||
|
||
*pdwEffect = DROPEFFECT_COPY; // Indicate that only copy operations are allowed | ||
return S_OK; | ||
} | ||
|
||
HRESULT DropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) { | ||
UNREFERENCED_PARAMETER(grfKeyState); | ||
UNREFERENCED_PARAMETER(pt); | ||
|
||
*pdwEffect = DROPEFFECT_COPY; // Continue to allow only copy operations | ||
return S_OK; | ||
} | ||
|
||
HRESULT DropTarget::DragLeave() { | ||
// Handle the drag leave event with minimal overhead | ||
return S_OK; | ||
} | ||
|
||
HRESULT DropTarget::Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) { | ||
UNREFERENCED_PARAMETER(grfKeyState); | ||
UNREFERENCED_PARAMETER(pt); | ||
|
||
try { | ||
STGMEDIUM stgMedium; | ||
FORMATETC formatEtc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; | ||
|
||
// Check if the data is in file format | ||
if (pDataObj->GetData(&formatEtc, &stgMedium) == S_OK) { | ||
HDROP hDrop = static_cast<HDROP>(GlobalLock(stgMedium.hGlobal)); | ||
if (hDrop) { | ||
UINT numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); | ||
if (numFiles > 0) { | ||
wchar_t filePath[MAX_PATH]; | ||
DragQueryFile(hDrop, 0, filePath, MAX_PATH); | ||
_parent->loadListFromCsv(filePath); // Load CSV file | ||
} | ||
GlobalUnlock(stgMedium.hGlobal); // Unlock the global memory object | ||
} | ||
ReleaseStgMedium(&stgMedium); // Release the storage medium | ||
} | ||
|
||
*pdwEffect = DROPEFFECT_COPY; // Indicate that the operation was a copy | ||
return S_OK; | ||
} | ||
catch (...) { | ||
// Handle errors silently | ||
*pdwEffect = DROPEFFECT_NONE; | ||
return E_FAIL; | ||
} | ||
} | ||
|
||
HRESULT DropTarget::QueryInterface(REFIID riid, void** ppvObject) { | ||
if (riid == IID_IUnknown || riid == IID_IDropTarget) { | ||
*ppvObject = this; | ||
AddRef(); | ||
return S_OK; | ||
} | ||
*ppvObject = nullptr; | ||
return E_NOINTERFACE; | ||
} | ||
|
||
ULONG DropTarget::AddRef() { | ||
return InterlockedIncrement(&_refCount); | ||
} | ||
|
||
ULONG DropTarget::Release() { | ||
ULONG count = InterlockedDecrement(&_refCount); | ||
if (count == 0) { | ||
delete this; | ||
} | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef DROP_TARGET_H | ||
#define DROP_TARGET_H | ||
|
||
#include <Windows.h> | ||
#include <shlobj.h> // Include for IDropTarget and other shell functions | ||
|
||
class MultiReplace; // Forward declaration to avoid circular dependency | ||
|
||
class DropTarget : public IDropTarget { | ||
public: | ||
DropTarget(HWND hwnd, MultiReplace* parent); | ||
virtual ~DropTarget() {} | ||
|
||
// Implement all IDropTarget methods | ||
HRESULT STDMETHODCALLTYPE DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override; | ||
HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override; | ||
HRESULT STDMETHODCALLTYPE DragLeave() override; | ||
HRESULT STDMETHODCALLTYPE Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override; | ||
|
||
// IUnknown methods | ||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override; | ||
ULONG STDMETHODCALLTYPE AddRef() override; | ||
ULONG STDMETHODCALLTYPE Release() override; | ||
|
||
private: | ||
LONG _refCount; | ||
HWND _hwnd; | ||
MultiReplace* _parent; | ||
}; | ||
|
||
#endif // DROP_TARGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters