|
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once
#include <shobjidl.h>
#include <shlobj.h>
#include <comdef.h>
#include "shelluuids.h"
#include "macros.h"
_COM_SMARTPTR_TYPEDEF(IColumnProvider, __uuidof(IColumnProvider));
namespace MSF
{
class CSHColumnInit : public SHCOLUMNINIT
{
public:
CSHColumnInit(const wchar_t* pwszFolder = NULL)
{
dwFlags = 0; // reserved.
dwReserved = 0;
if (pwszFolder == NULL)
{
wszFolder[0] = 0;
}
else
{
lstrcpynW(wszFolder, pwszFolder, MSF_ARRAY_SIZE(wszFolder));
}
}
};
class IColumnProviderPtr :
public ::IColumnProviderPtr
{
public:
IColumnProviderPtr(const CLSID& clsid, IUnknown* pOuter, DWORD dwClsContext) :
::IColumnProviderPtr(clsid, pOuter, dwClsContext)
{
}
IColumnProviderPtr(const CLSID& clsid, wchar_t* pwszFolder = NULL) :
::IColumnProviderPtr(clsid, NULL, CLSCTX_INPROC_SERVER)
{
Initialize(pwszFolder);
}
void CreateInstance(const CLSID& rclsid)
{
RaiseExceptionIfFailed(__super::CreateInstance(rclsid));
}
void Initialize(wchar_t* pwszFolder = NULL)
{
CSHColumnInit shcolumninit(pwszFolder);
RaiseExceptionIfFailed(GetInterfacePtr()->Initialize(&shcolumninit));
}
bool GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO& columninfo)
{
HRESULT hr = GetInterfacePtr()->GetColumnInfo(dwIndex, &columninfo);
RaiseExceptionIfFailed(hr);
return hr == S_OK;
}
// Helper that retrieves id as return or throws.
SHCOLUMNID GetColumnId(DWORD dwIndex)
{
SHCOLUMNINFO columninfo;
RaiseExceptionIf(!GetColumnInfo(dwIndex, columninfo));
return columninfo.scid;
}
unsigned long GetColumnCount()
{
DWORD dwIndex = 0;
SHCOLUMNINFO columninfo;
while (GetColumnInfo(dwIndex, columninfo))
{
++dwIndex;
}
return dwIndex;
}
bool GetItemData(const wchar_t* wszFilename, SHCOLUMNID& scid, VARIANT& varData)
{
CShColumnData shcolumndata(wszFilename);
HRESULT hr = GetInterfacePtr()->GetItemData(&scid, &shcolumndata, &varData);
RaiseExceptionIfFailed(hr);
return hr == S_OK;
}
_variant_t GetItemData(const wchar_t* wszFilename, SHCOLUMNID& scid)
{
_variant_t varData;
RaiseExceptionIf(!GetItemData(wszFilename, scid, varData));
return varData;
}
private:
class CShColumnData : public SHCOLUMNDATA
{
public:
CShColumnData(const wchar_t* wszFilename, ULONG dwflags = 0, DWORD dwfileattributes = FILE_ATTRIBUTE_NORMAL)
{
dwFlags = dwflags;
dwFileAttributes = dwfileattributes;
dwReserved = 0;
lstrcpynW(wszFile, wszFilename, MSF_ARRAY_SIZE(wszFile));
wcscpy(wszFile, wszFilename);
pwszExt = wcsrchr(wszFile, '.');
}
};
};
} // 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.