mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-30 06:07:56 +08:00
a743e496c5
* Changes to fix warning 26493 on src/common It will be multi PR change. This does not turn on the rule but fix the code under src/commom * int cast
68 lines
1.2 KiB
C++
68 lines
1.2 KiB
C++
#pragma once
|
|
#include <shellapi.h>
|
|
|
|
class HDropIterator
|
|
{
|
|
public:
|
|
HDropIterator(IDataObject* pDataObject)
|
|
{
|
|
_current = 0;
|
|
_listCount = 0;
|
|
|
|
FORMATETC formatetc = {
|
|
CF_HDROP,
|
|
NULL,
|
|
DVASPECT_CONTENT,
|
|
-1,
|
|
TYMED_HGLOBAL
|
|
};
|
|
|
|
if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium)))
|
|
{
|
|
_listCount = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), 0xFFFFFFFF, NULL, 0);
|
|
}
|
|
else
|
|
{
|
|
m_medium = {};
|
|
}
|
|
}
|
|
|
|
~HDropIterator()
|
|
{
|
|
if (m_medium.tymed)
|
|
{
|
|
ReleaseStgMedium(&m_medium);
|
|
}
|
|
}
|
|
|
|
void First()
|
|
{
|
|
_current = 0;
|
|
}
|
|
|
|
void Next()
|
|
{
|
|
_current++;
|
|
}
|
|
|
|
bool IsDone() const
|
|
{
|
|
return _current >= _listCount;
|
|
}
|
|
|
|
LPTSTR CurrentItem() const
|
|
{
|
|
UINT cch = DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, NULL, 0) + 1;
|
|
LPTSTR pszPath = static_cast<LPTSTR>(malloc(sizeof(TCHAR) * cch));
|
|
|
|
DragQueryFile(static_cast<HDROP>(m_medium.hGlobal), _current, pszPath, cch);
|
|
|
|
return pszPath;
|
|
}
|
|
|
|
private:
|
|
UINT _listCount;
|
|
STGMEDIUM m_medium;
|
|
UINT _current;
|
|
};
|