2021-10-25 21:40:19 +08:00
|
|
|
#pragma once
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
|
|
|
class HDropIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HDropIterator(IDataObject* pDataObject)
|
|
|
|
{
|
|
|
|
_current = 0;
|
2022-10-03 18:13:48 +08:00
|
|
|
_listCount = 0;
|
2021-10-25 21:40:19 +08:00
|
|
|
|
|
|
|
FORMATETC formatetc = {
|
|
|
|
CF_HDROP,
|
|
|
|
NULL,
|
|
|
|
DVASPECT_CONTENT,
|
|
|
|
-1,
|
|
|
|
TYMED_HGLOBAL
|
|
|
|
};
|
|
|
|
|
2022-10-03 18:13:48 +08:00
|
|
|
if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium)))
|
|
|
|
{
|
2023-02-08 19:00:19 +08:00
|
|
|
_listCount = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), 0xFFFFFFFF, NULL, 0);
|
2022-10-03 18:13:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_medium = {};
|
|
|
|
}
|
2021-10-25 21:40:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~HDropIterator()
|
|
|
|
{
|
2022-10-03 18:13:48 +08:00
|
|
|
if (m_medium.tymed)
|
|
|
|
{
|
|
|
|
ReleaseStgMedium(&m_medium);
|
|
|
|
}
|
2021-10-25 21:40:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void First()
|
|
|
|
{
|
|
|
|
_current = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Next()
|
|
|
|
{
|
|
|
|
_current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDone() const
|
|
|
|
{
|
|
|
|
return _current >= _listCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPTSTR CurrentItem() const
|
|
|
|
{
|
2023-02-08 19:00:19 +08:00
|
|
|
UINT cch = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, NULL, 0) + 1;
|
|
|
|
LPTSTR pszPath = static_cast<LPTSTR>(malloc(sizeof(TCHAR) * cch));
|
2021-10-25 21:40:19 +08:00
|
|
|
|
2023-02-08 19:00:19 +08:00
|
|
|
DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, pszPath, cch);
|
2021-10-25 21:40:19 +08:00
|
|
|
|
|
|
|
return pszPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
UINT _listCount;
|
|
|
|
STGMEDIUM m_medium;
|
|
|
|
UINT _current;
|
|
|
|
};
|