|
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once
#include "cfhdrop.h"
#include "dataobjectptr.h"
#include "catchhandler.h"
namespace MSF
{
class IShellExtInitImpl : public IShellExtInit
{
public:
// IShellExtInit
STDMETHOD(Initialize)(const ITEMIDLIST* /*pidlFolder*/, IDataObject* pDataObject, HKEY /*hkeyProgID*/)
{
ATLTRACE2(atlTraceCOM, 0, _T("IContextMenuImpl::Initialize (instance=%p)\n"), this);
ATLASSERT(pDataObject != NULL && "Invalid argument");
try
{
CacheFiles(pDataObject);
return S_OK;
}
MSF_COM_CATCH_HANDLER()
}
protected:
typedef std::vector<CString> CStrings;
void RegisterExtension(CString strExtension)
{
m_extensions.push_back(strExtension.MakeLower());
}
void CacheFiles(IDataObject* pDataObject)
{
CCfHDrop cfhdrop(pDataObject);
m_filenames.clear();
const unsigned int uFiles = cfhdrop.GetFileCount();
for (unsigned int i = 0; i < uFiles; ++i)
{
CString strFilename = cfhdrop.GetFile(i);
m_filenames.push_back(strFilename);
}
}
// Purpose: helper function, can be used to filter unsupported filename in a collection.
bool ContainsUnknownExtension(const CStrings& filenames) const
{
for (CStrings::const_iterator it = filenames.begin(); it != filenames.end(); ++it)
{
if (IsUnknownExtension(*it))
return true; // found at least 1 unknown extension.
}
return false;
}
bool IsUnknownExtension(const TCHAR* szFileName) const
{
CString strExtension(PathFindExtension(szFileName));
strExtension.MakeLower();
CStrings::const_iterator result =
std::find(m_extensions.begin(), m_extensions.end(), strExtension);
return result == m_extensions.end();
}
const CStrings& GetFilenames() const
{
return m_filenames;
}
private:
// Member variables.
CStrings m_extensions;
CStrings m_filenames;
};
} // end MSF namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and works Hitachi High-Tech Analytical Science.