本文整理汇总了C++中IShellFolder::EnumObjects方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellFolder::EnumObjects方法的具体用法?C++ IShellFolder::EnumObjects怎么用?C++ IShellFolder::EnumObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellFolder
的用法示例。
在下文中一共展示了IShellFolder::EnumObjects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SimpleEnumFolder
/**
* 简单的枚举文件夹内容,返回内容数量
*/
int SimpleEnumFolder(LPCTSTR lpszPath // 文件夹路径
, CShellManager* pShellManager // Shell管理器
, function<void(LPITEMIDLIST)> filter) // 过滤器函数
{
ENSURE(lpszPath != nullptr);
ASSERT_VALID(pShellManager);
AFX_SHELLITEMINFO info;
HRESULT hr = pShellManager->ItemFromPath(lpszPath, info.pidlRel);
if (FAILED(hr)) {
return 0;
}
int nFolderCount = 0;
LPSHELLFOLDER pDesktopFolder;
hr = SHGetDesktopFolder(&pDesktopFolder);
if (SUCCEEDED(hr)) {
IShellFolder* psfCurFolder = nullptr;
hr = pDesktopFolder->BindToObject(info.pidlRel, nullptr, IID_IShellFolder, (LPVOID*)&psfCurFolder);
LPENUMIDLIST pEnum = nullptr;
HRESULT hRes = psfCurFolder->EnumObjects(nullptr, (SHCONTF)(SHCONTF_FOLDERS), &pEnum);
if (SUCCEEDED(hRes) && pEnum != nullptr) {
DWORD dwFetched = 1;
LPITEMIDLIST pidlTemp;
while (pEnum->Next(1, &pidlTemp, &dwFetched) == S_OK && dwFetched) {
if (!filter._Empty()) {
LPITEMIDLIST itemID = pShellManager->ConcatenateItem(info.pidlRel, pidlTemp);
filter(itemID);
pShellManager->FreeItem(itemID);
}
pShellManager->FreeItem(pidlTemp);
nFolderCount++;
dwFetched = 0;
}
pEnum->Release();
}
psfCurFolder->Release();
pDesktopFolder->Release();
}
pShellManager->FreeItem(info.pidlRel);
return nFolderCount;
}
示例2: GetAllFavorites
PFAVORITELIST CFavoriteEngine::GetAllFavorites(){
if(FAILED(CoInitialize(NULL)))
return NULL;
HRESULT hRet = ::SHGetMalloc(&m_pMalloc);
if(FAILED(hRet)){
m_pMalloc->Release();
return NULL;
}
LPITEMIDLIST pidl;
hRet = ::SHGetSpecialFolderLocation( NULL, CSIDL_FAVORITES, &pidl);
if(FAILED(hRet)){
m_pMalloc->Release();
return NULL;
}
IShellFolder *pShellFolder = NULL;
hRet = ::SHGetDesktopFolder (&pShellFolder);
if (FAILED (hRet)){
m_pMalloc->Free (pidl);
m_pMalloc->Release ();
return NULL;
}
IShellFolder *pFavFolder = NULL;
hRet = pShellFolder->BindToObject (pidl, NULL, IID_IShellFolder, reinterpret_cast<void **>(&pFavFolder));
long nItems = 0;
IEnumIDList* pItems = NULL;
hRet = pFavFolder->EnumObjects(NULL, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS, &pItems);
if(m_pFavoListRoot){
CleanUp();
}
m_pFavoListRoot = new FAVORITELIST;
ZeroMemory(m_pFavoListRoot, sizeof(FAVORITELIST));
PFAVORITELIST pFavoListCur = GetFavorite( pFavFolder, m_pFavoListRoot, pItems);
if (NULL != pItems){
pItems->Release();
}
m_pMalloc->Free(pidl);
m_pMalloc->Release();
return m_pFavoListRoot;
}
示例3: return
/*
* Class: sun_awt_shell_Win32ShellFolder2
* Method: getEnumObjects
* Signature: (JZ)J
*/
JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getEnumObjects
(JNIEnv* env, jobject folder, jlong pIShellFolder,
jboolean isDesktop, jboolean includeHiddenFiles)
{
IShellFolder* pFolder = (IShellFolder*)pIShellFolder;
if (pFolder == NULL) {
return 0;
}
DWORD dwFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
if (includeHiddenFiles) {
dwFlags |= SHCONTF_INCLUDEHIDDEN;
}
/*
if (!isDesktop) {
dwFlags = dwFlags | SHCONTF_NONFOLDERS;
}
*/
IEnumIDList* pEnum;
if (pFolder->EnumObjects(NULL, dwFlags, &pEnum) != S_OK) {
return 0;
}
return (jlong)pEnum;
}
示例4: GetDrives
void GetDrives (CDriveArray &array)
{
array.clear ();
IShellFolder *psfDesktop;
SHGetDesktopFolder(&psfDesktop);
if(psfDesktop == NULL)
return;
LPITEMIDLIST pidlMyComputer;
SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlMyComputer);
if(pidlMyComputer == NULL)
{
psfDesktop->Release();
return;
}
IShellFolder *psfMyComputer;
psfDesktop->BindToObject(pidlMyComputer, NULL, IID_IShellFolder, (LPVOID*)&psfMyComputer);
if(psfMyComputer)
{
IEnumIDList* pEnum;
if(SUCCEEDED(psfMyComputer->EnumObjects(NULL, SHCONTF_FOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum)))
{
ITEMIDLIST* pidl;
DWORD dwFetched = 1;
TCHAR path[MAX_PATH];
while(SUCCEEDED(pEnum->Next(1, &pidl, &dwFetched)) && dwFetched)
{
SHFILEINFO sfi;
//LPITEMIDLIST pidl_full = Pidl_Concatenate (pidlMyComputer, pidl);
LPITEMIDLIST pidl_full = ILCombine (pidlMyComputer, pidl);
SHGetPathFromIDList (pidl_full, path);
UINT nType = GetDriveType( path);
// if( DRIVE_REMOVABLE < nType && nType <= DRIVE_RAMDISK )
if( nType != DRIVE_UNKNOWN && nType != DRIVE_NO_ROOT_DIR )
if(SHGetFileInfo((LPCTSTR)pidl_full, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_LINKOVERLAY))
{
CDriveInfo info;
info.m_Name = sfi.szDisplayName;
info.m_Path = path;
info.m_Type = sfi.szTypeName;
info.m_nImage = sfi.iIcon;
info.m_nType = nType;
DWORD SectorsPerCluster; // sectors per cluster
DWORD BytesPerSector; // bytes per sector
DWORD NumberOfFreeClusters; // free clusters
DWORD TotalNumberOfClusters; // total clusters
// TRACE (L"%s %s\n", sfi.szDisplayName, path);
if (nType != DRIVE_REMOVABLE )
if (GetDiskFreeSpace (path, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters))
{
DWORD BytesPerCluster = BytesPerSector * SectorsPerCluster;
info.m_FreeSpace = UInt32x32To64(NumberOfFreeClusters, BytesPerCluster);
info.m_TotalSize= UInt32x32To64(TotalNumberOfClusters, BytesPerCluster);
}
array.push_back (info);
}
}
pEnum->Release ();
}
psfMyComputer->Release();
}
CoTaskMemFree(pidlMyComputer);
psfDesktop->Release();
}
示例5: while
const FileItemList& FileItem::getChildren()
{
// Is the file-item a folder?
if (IS_FOLDER(this) &&
// if the children list is empty, or the file-system version
// change (it's like to say: the current this->children list
// is outdated)...
(this->children.empty() ||
current_file_system_version > this->version)) {
FileItemList::iterator it;
FileItem* child;
// we have to mark current items as deprecated
for (it=this->children.begin();
it!=this->children.end(); ++it) {
child = static_cast<FileItem*>(*it);
child->removed = true;
}
//PRINTF("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname);
#ifdef USE_PIDLS
{
IShellFolder* pFolder = NULL;
if (this == rootitem)
pFolder = shl_idesktop;
else
shl_idesktop->BindToObject(this->fullpidl,
NULL,
IID_IShellFolder,
(LPVOID *)&pFolder);
if (pFolder != NULL) {
IEnumIDList *pEnum = NULL;
ULONG c, fetched;
/* get the interface to enumerate subitems */
pFolder->EnumObjects(win_get_window(),
SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);
if (pEnum != NULL) {
LPITEMIDLIST itempidl[256];
SFGAOF attribs[256];
/* enumerate the items in the folder */
while (pEnum->Next(256, itempidl, &fetched) == S_OK && fetched > 0) {
/* request the SFGAO_FOLDER attribute to know what of the
item is a folder */
for (c=0; c<fetched; ++c) {
attribs[c] = SFGAO_FOLDER;
pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c);
}
/* generate the FileItems */
for (c=0; c<fetched; ++c) {
LPITEMIDLIST fullpidl = concat_pidl(this->fullpidl,
itempidl[c]);
child = get_fileitem_by_fullpidl(fullpidl, false);
if (!child) {
child = new FileItem(this);
child->pidl = itempidl[c];
child->fullpidl = fullpidl;
child->attrib = attribs[c];
update_by_pidl(child);
put_fileitem(child);
}
else {
ASSERT(child->parent == this);
free_pidl(fullpidl);
free_pidl(itempidl[c]);
}
this->insertChildSorted(child);
}
}
pEnum->Release();
}
if (pFolder != shl_idesktop)
pFolder->Release();
}
}
#else
{
char buf[MAX_PATH], path[MAX_PATH], tmp[32];
ustrcpy(path, this->filename.c_str());
put_backslash(path);
replace_filename(buf,
path,
uconvert_ascii("*.*", tmp),
sizeof(buf));
#ifdef WORKAROUND_64BITS_SUPPORT
// we cannot use the for_each_file's 'param' to wrap a 64-bits pointer
//.........这里部分代码省略.........
示例6: BrowseVirtualFolder
void CShellBrowser::BrowseVirtualFolder(LPITEMIDLIST pidlDirectory)
{
IShellFolder *pShellFolder = NULL;
IEnumIDList *pEnumIDList = NULL;
LPITEMIDLIST rgelt = NULL;
STRRET str;
SHCONTF EnumFlags;
TCHAR szFileName[MAX_PATH];
ULONG uFetched;
HRESULT hr;
DetermineFolderVirtual(pidlDirectory);
hr = BindToIdl(pidlDirectory, IID_PPV_ARGS(&pShellFolder));
if(SUCCEEDED(hr))
{
m_pidlDirectory = ILClone(pidlDirectory);
EnumFlags = SHCONTF_FOLDERS|SHCONTF_NONFOLDERS;
if(m_bShowHidden)
EnumFlags |= SHCONTF_INCLUDEHIDDEN;
hr = pShellFolder->EnumObjects(m_hOwner,EnumFlags,&pEnumIDList);
if(SUCCEEDED(hr) && pEnumIDList != NULL)
{
uFetched = 1;
while(pEnumIDList->Next(1,&rgelt,&uFetched) == S_OK && (uFetched == 1))
{
ULONG uAttributes = SFGAO_FOLDER;
pShellFolder->GetAttributesOf(1,(LPCITEMIDLIST *)&rgelt,&uAttributes);
/* If this is a virtual folder, only use SHGDN_INFOLDER. If this is
a real folder, combine SHGDN_INFOLDER with SHGDN_FORPARSING. This is
so that items in real folders can still be shown with extensions, even
if the global, Explorer option is disabled.
Also use only SHGDN_INFOLDER if this item is a folder. This is to ensure
that specific folders in Windows 7 (those under C:\Users\Username) appear
correctly. */
if(m_bVirtualFolder || (uAttributes & SFGAO_FOLDER))
hr = pShellFolder->GetDisplayNameOf(rgelt,SHGDN_INFOLDER,&str);
else
hr = pShellFolder->GetDisplayNameOf(rgelt,SHGDN_INFOLDER|SHGDN_FORPARSING,&str);
if(SUCCEEDED(hr))
{
StrRetToBuf(&str,rgelt,szFileName,MAX_PATH);
AddItemInternal(pidlDirectory,rgelt,szFileName,-1,FALSE);
}
CoTaskMemFree((LPVOID)rgelt);
}
pEnumIDList->Release();
}
pShellFolder->Release();
}
}