/** * 简单的枚举文件夹内容,返回内容数量 */ 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; }
void CRecBinViewer::FillFolder () { LPENUMIDLIST penumFiles = NULL; LPITEMIDLIST pidl = NULL; PSHELLDETAILS pDetails = NULL; SHELLDETAILS sd; int iSubItem = 0; HRESULT hr = S_OK; CString csTemp; hr = m_pRecycleBin->CreateViewObject (m_hWnd, IID_IShellDetails, (LPVOID*)&pDetails); // Iterate through list m_pRecycleBin->EnumObjects(m_hWnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS| SHCONTF_INCLUDEHIDDEN, &penumFiles); CStringAr ar; if (SUCCEEDED (hr)) { while (penumFiles->Next(1, &pidl, NULL) != S_FALSE) { ar.clear (); hr = S_OK; iSubItem = 0; while (SUCCEEDED (hr)) { hr = pDetails->GetDetailsOf (pidl , iSubItem, &sd); if (SUCCEEDED (hr)) { GetName (sd.str, csTemp); ar.push_back (csTemp); iSubItem++; if (iSubItem > MAX_COLUMN) break; } } m_List.push_back (CRecycleItem (ar, pidl)); } } CoTaskMemFree (pDetails); if (NULL != penumFiles) { penumFiles->Release (); penumFiles = NULL; } }
HRESULT CSEShellView::_Init(CSEShellFolder* pFolder,LPCITEMIDLIST pidlRoot) { TRACE_FUNCTION(); assert(pFolder); if( pFolder==NULL ) { TRACE_RETURN E_FAIL; } m_pFolder = pFolder; m_pFolder->AddRef(); m_pidlRoot=m_pidlManager.Copy(pidlRoot); LPENUMIDLIST pEnum; m_pFolder->EnumObjects( NULL, -1, &pEnum ); pEnum->Release(); TRACE_RETURN S_OK; }
void CRecBinViewer::FillFolder2 () { CString csTemp; LPENUMIDLIST penumFiles; LPITEMIDLIST pidl = NULL; SHELLDETAILS sd; int iSubItem = 0; CStringAr ar; // Get the list of available objects HRESULT hr = m_pFolder2->EnumObjects(m_hWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS| SHCONTF_INCLUDEHIDDEN, &penumFiles); if (SUCCEEDED (hr)) { // Iterate through list while (penumFiles->Next(1, &pidl, NULL) != S_FALSE) { ar.clear (); // iItem = m_List.InsertItem (iItem, EMPTYSTR); // m_List.SetItemData (iItem, (DWORD)pidl); /*ZeroMemory (&fi, sizeof (fi)); hr = SHGetFileInfo ((LPCTSTR)pidl, 0, &fi, sizeof (fi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL); if (SUCCEEDED (hr)) { iIndex = fi.iIcon; m_List.SetItem (iItem, 0, LVIF_IMAGE, NULL, iIndex, 0, 0, 0); }*/ // We iterate now in all the available columns. // Since it depends on the system, we "hope" that they are going to be as many // and in the same order as when we have added the column's headers. hr = S_OK; iSubItem = 0; while (SUCCEEDED (hr)) { hr = m_pFolder2->GetDetailsOf (pidl , iSubItem, &sd); if (SUCCEEDED (hr)) { GetName (sd.str, csTemp); ar.push_back (csTemp); //m_List.SetItemText (iItem, iSubItem , szTemp); iSubItem ++; if (iSubItem > MAX_COLUMN) break; } } m_List.push_back (CRecycleItem (ar, pidl)); //m_List.push_back (ar); } } if (NULL != penumFiles) { penumFiles->Release (); penumFiles = NULL; } }
/* #FN# Fills a branch of the TreeView control. Given the shell folder, enumerate the subitems of this folder, and add the appropriate items to the tree. This function enumerates the items in the folder identifed by lpsf. Note that since we are filling the left hand pane, we will only add items that are folders and/or have sub-folders. We *could* put all items in here if we wanted, but that's not the intent. */ void /* #AS# Nothing */ CShellTree:: FillTreeView( LPSHELLFOLDER lpsf, /* #IN# Pointer to shell folder that we want to enumerate items */ LPITEMIDLIST lpifq, /* #IN# Fully qualified item id list to the item that we are enumerating items for; in other words, this is the PIDL to the item identified by the lpsf parameter */ HTREEITEM hParent /* #IN# Parent node */ ) { TV_ITEM tvi; /* TreeView Item */ TV_INSERTSTRUCT tvins; /* TreeView Insert Struct */ HTREEITEM hPrev = NULL; /* Previous Item Added */ LPSHELLFOLDER lpsf2 = NULL; LPENUMIDLIST lpe = NULL; LPITEMIDLIST lpi = NULL; LPITEMIDLIST lpifqThisItem = NULL; LPTVITEMDATA lptvid = NULL; LPMALLOC lpMalloc = NULL; ULONG ulFetched = 0; HWND hwnd = ::GetParent( m_hWnd ); char szBuff[ MAX_PATH + 1 ]; char szPath[ MAX_PATH + 1 ]; HRESULT hr; /* Allocate a shell memory object */ hr = ::SHGetMalloc( &lpMalloc ); if( FAILED(hr) ) return; if( SUCCEEDED(hr) ) { /* Get the IEnumIDList object for the given folder */ hr = lpsf->EnumObjects( hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &lpe ); if( S_OK == hr && lpe ) { /* Enumerate throught the list of folder and non-folder objects */ while( S_OK == lpe->Next( 1, &lpi, &ulFetched ) ) { /* Create a fully qualified path to the current item. The SH* shell API's take a fully qualified path pidl, (see GetIcon above where I call SHGetFileInfo) whereas the interface methods take a relative path pidl */ ULONG ulAttrs = SFGAO_FOLDER | SFGAO_HASSUBFOLDER; if( !m_bFolderMode ) ulAttrs |= SFGAO_FILESYSTEM | SFGAO_LINK; /* Determine what type of object we have */ lpsf->GetAttributesOf( 1, (const struct _ITEMIDLIST **)&lpi, &ulAttrs ); if( m_bFolderMode && ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER) || (!m_bFolderMode && ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_FILESYSTEM) && !(ulAttrs & SFGAO_LINK)) ) { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; /* We need this next if statement so that we don't add things like the MSN to our tree. MSN is not a folder, but according to the shell it has subfolders */ /* OK, let's get some memory for our ITEMDATA struct */ lptvid = (LPTVITEMDATA)lpMalloc->Alloc( sizeof(TVITEMDATA) ); if( !lptvid ) goto Done; /* Error - could not allocate memory */ /* Now get the friendly name that we'll put in the treeview */ if( !GetName( lpsf, lpi, SHGDN_NORMAL, szBuff ) ) goto Done; /* Error - could not get friendly name */ tvi.pszText = szBuff; tvi.cchTextMax = MAX_PATH; /* Allocate/create the fully qualified PIDL, consisting of the parents full PIDL and our relative PIDL */ lpifqThisItem = ConcatPidls( lpifq, lpi ); if( ulAttrs & SFGAO_FOLDER && (ulAttrs & SFGAO_HASSUBFOLDER || /* There are not any subfolders but what about files? */ (!m_bFolderMode && SHGetPathFromIDList( lpifqThisItem, szPath ) && !IsFolderEmpty( szPath ))) ) { /* This item has sub-folders, so let's put the + in the TreeView. The first time the user clicks on the item, we'll populate the sub-folders */ tvi.cChildren = 1; tvi.mask |= TVIF_CHILDREN; } /* Now, make a copy of the ITEMIDLIST (non-qualified) */ lptvid->lpi = CopyITEMID( lpMalloc, lpi ); tvi.iImage = GetItemIcon( lpifqThisItem, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON ); tvi.iSelectedImage = GetItemIcon( lpifqThisItem, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON ); lptvid->lpsfParent = lpsf; /* Store the parent folders SF */ lpsf->AddRef(); /* Increment our saved reference */ /* Now create another PIDL from our Full parents PIDL and the releative one that we'll save */ lptvid->lpifq = ConcatPidls( lpifq, lpi ); /* Populate the TreeView Insert Struct. The item is the one filled above. Insert it after the last item inserted at this level. And indicate this is a root entry */ tvi.lParam = (LPARAM)lptvid; tvins.item = tvi; tvins.hInsertAfter = hPrev; tvins.hParent = hParent; /* Add the item to the tree */ hPrev = InsertItem( &tvins ); /* Free this item with task allocator */ lpMalloc->Free( lpifqThisItem ); lpifqThisItem = 0; } lpMalloc->Free( lpi ); /* Free the pidl that the shell gave us */ lpi = 0; } } } else return; Done: if( lpe ) lpe->Release(); /* The following 2 if statements will only be TRUE if we got here on an error condition from the "goto" statement. Otherwise, we free this memory at the end of the while loop above */ if( lpi && lpMalloc ) lpMalloc->Free( lpi ); if( lpifqThisItem && lpMalloc ) lpMalloc->Free( lpifqThisItem ); if( lpMalloc ) lpMalloc->Release(); } /* #OF# CShellTree::FillTreeView */
HRESULT CSEShellView::Refresh(void) { TRACE_FUNCTION(); Clear(); if ( !m_pFolder ) { return E_NOTIMPL; } LPENUMIDLIST pEnumIDList = NULL; HRESULT hr = m_pFolder->EnumObjects( m_hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList); if ( FAILED(hr) ) { return hr; } { // 更新状态栏 LRESULT lResult; INT nPartArray[1] = { -1 }; m_pShellBrowser->SendControlMsg(FCW_STATUS, SB_SETPARTS, 1, (LPARAM)nPartArray, &lResult); TCHAR szInfo[128] = { 0 }; TCHAR* pszInfo = (TCHAR*)szInfo; CPidlEnum* pEnumInstance = (CPidlEnum*)((DWORD_PTR)pEnumIDList-offsetofclass( IEnumIDList, CPidlEnum )); int nPos = _sntprintf( pszInfo, 128, _T("虚拟网盘"), pEnumInstance->GetAllItemCount() ); //if ( pEnumInstance->GetHideItemCount() > 0 // && !pEnumInstance->IsIncludeHide() ) //{ // _sntprintf( pszInfo+nPos, 128-nPos, _T("(加 %d 个隐藏对象)"), pEnumInstance->GetHideItemCount() ); //} m_pShellBrowser->SendControlMsg(FCW_STATUS, SB_SETTEXT, 0, (LPARAM)szInfo, &lResult); } pEnumIDList->Reset(); LPITEMIDLIST lpItem = NULL; while( S_OK == pEnumIDList->Next( 1, &lpItem, NULL ) ) { const TCHAR* pszName = m_pidlManager.GetItemName( m_pidlManager.GetLastItem( lpItem ) ); if ( pszName ) { LVITEM item; item.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; item.iItem = ListView_GetItemCount( m_hWnd ); item.iSubItem = 0; item.pszText = (LPTSTR)pszName; item.state = 0; item.stateMask = 0; item.lParam = (LPARAM)(LONG_PTR)lpItem; SHFILEINFO sfi; if( m_pidlManager.GetItemType(lpItem) == CPidlManager::FOLDER ) { LPITEMIDLIST pidl = NULL; pidl = m_pidlManager.Concatenate( m_pFolder->GetRootPath(), lpItem ); TCHAR szPath[MAX_PATH] = {0}; DWORD dwLen = MAX_PATH; m_pidlManager.GetFullName( pidl, szPath, &dwLen ); m_pidlManager.ReplaceRoot( szPath ); m_pidlManager.Delete( pidl ); SHGetFileInfo (szPath,\ NULL, &sfi, sizeof (sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); item.iImage = sfi.iIcon; } else { SHGetFileInfo (pszName,\ FILE_ATTRIBUTE_NORMAL, &sfi, sizeof (sfi), SHGFI_USEFILEATTRIBUTES|SHGFI_SYSICONINDEX | SHGFI_SMALLICON); item.iImage = sfi.iIcon; } int nItem = ListView_InsertItem( m_hWnd, &item ); if( m_pidlManager.GetItemType(lpItem) == CPidlManager::FOLDER ) { ListView_SetItemText( m_hWnd, nItem, 2, _T("文件夹") ); } else { LPTSTR pExt = StrChrI( pszName, _T('.') ); if ( pExt ) { ++pExt; ListView_SetItemText( m_hWnd, nItem, 2, pExt ); } else { ListView_SetItemText( m_hWnd, nItem, 2, _T("未知文件") ); } } } } pEnumIDList->Release(); TRACE_RETURN S_OK; }
int DriveBox_Fill(HWND hwnd) { LPSHELLFOLDER lpsfDesktop; LPSHELLFOLDER lpsf; // Workspace == CSIDL_DRIVES LPITEMIDLIST pidl; LPITEMIDLIST pidlEntry; LPENUMIDLIST lpe; COMBOBOXEXITEM cbei; LPDC_ITEMDATA lpdcid; ULONG dwAttributes = 0; DWORD grfFlags = SHCONTF_FOLDERS; // Init ComboBox SendMessage(hwnd, WM_SETREDRAW, 0, 0); SendMessage(hwnd, CB_RESETCONTENT, 0, 0); ZeroMemory(&cbei, sizeof(COMBOBOXEXITEM)); cbei.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_LPARAM; cbei.pszText = LPSTR_TEXTCALLBACK; cbei.cchTextMax = MAX_PATH; cbei.iImage = I_IMAGECALLBACK; cbei.iSelectedImage = I_IMAGECALLBACK; // Get pidl to [My Computer] if (NOERROR == SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &pidl)) { // Get Desktop Folder if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) { // Bind pidl to IShellFolder if (NOERROR == lpsfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&lpsf)) { // Create an Enumeration object for lpsf if (NOERROR == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) { // Enumerate the contents of [My Computer] while (NOERROR == lpe->Next(1, &pidlEntry, NULL)) { // Add item to the List if it is part of the // Filesystem dwAttributes = SFGAO_FILESYSTEM; lpsf->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlEntry, &dwAttributes); if (dwAttributes & SFGAO_FILESYSTEM) { // Windows XP: check if pidlEntry is a drive SHDESCRIPTIONID di; HRESULT hr; hr = SHGetDataFromIDList(lpsf, pidlEntry, SHGDFIL_DESCRIPTIONID, &di, sizeof(SHDESCRIPTIONID)); if (hr != NOERROR || (di.dwDescriptionId >= SHDID_COMPUTER_DRIVE35 && di.dwDescriptionId <= SHDID_COMPUTER_OTHER)) { lpdcid = (DC_ITEMDATA*)CoTaskMemAlloc(sizeof(DC_ITEMDATA)); // lpdcid->pidl = IL_Copy(pidlEntry); lpdcid->pidl = pidlEntry; lpdcid->lpsf = lpsf; lpsf->AddRef(); // Insert sorted ... { COMBOBOXEXITEM cbei2; LPDC_ITEMDATA lpdcid2; HRESULT hr; cbei2.mask = CBEIF_LPARAM; cbei2.iItem = 0; while ((SendMessage(hwnd, CBEM_GETITEM, 0, (LPARAM)&cbei2))) { lpdcid2 = (LPDC_ITEMDATA)cbei2.lParam; hr = (lpdcid->lpsf->CompareIDs(0, lpdcid->pidl, lpdcid2->pidl)); if ((short)(SCODE_CODE(GetScode(hr))) < 0) break; else cbei2.iItem++; } cbei.iItem = cbei2.iItem; cbei.lParam = (LPARAM)lpdcid; SendMessage(hwnd, CBEM_INSERTITEM, 0, (LPARAM)&cbei); } } } } // IEnumIDList::Next() lpe->Release(); } // IShellFolder::EnumObjects() lpsf->Release(); } // IShellFolder::BindToObject() CoTaskMemFree(pidl); } // SHGetSpecialFolderLocation() lpsfDesktop->Release(); } // SHGetDesktopFolder() SendMessage(hwnd, WM_SETREDRAW, 1, 0); // Return number of items added to combo box return ((int)SendMessage(hwnd, CB_GETCOUNT, 0, 0)); }
// Snapshots a directory and displays the items in the listview control int DirList_Fill(HWND hwnd, const WCHAR* lpszDir, DWORD grfFlags, const WCHAR* lpszFileSpec, BOOL bExcludeFilter, BOOL bNoFadeHidden, int iSortFlags, BOOL fSortRev) { WCHAR wszDir[MAX_PATH]; LPSHELLFOLDER lpsfDesktop = NULL; LPSHELLFOLDER lpsf = NULL; LPITEMIDLIST pidl = NULL; LPITEMIDLIST pidlEntry = NULL; LPENUMIDLIST lpe = NULL; LV_ITEM lvi; LPLV_ITEMDATA lplvid; ULONG chParsed = 0; ULONG dwAttributes = 0; DL_FILTER dlf; SHFILEINFO shfi = { 0 }; DLDATA* lpdl = (DLDATA*)GetProp(hwnd, pDirListProp); // Initialize default icons SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO), SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX); lpdl->iDefIconFolder = shfi.iIcon; SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO), SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX); lpdl->iDefIconFile = shfi.iIcon; // First of all terminate running icon thread DirList_TerminateIconThread(hwnd); // A Directory is strongly required if (!lpszDir || !*lpszDir) return (-1); lstrcpy(lpdl->szPath, lpszDir); // Init ListView SendMessage(hwnd, WM_SETREDRAW, 0, 0); ListView_DeleteAllItems(hwnd); // Init Filter DirList_CreateFilter(&dlf, lpszFileSpec, bExcludeFilter); // Init lvi lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = LPSTR_TEXTCALLBACK; lvi.cchTextMax = MAX_PATH; lvi.iImage = I_IMAGECALLBACK; // Convert Directory to a UNICODE string /*MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszDir, -1, wszDir, MAX_PATH);*/ lstrcpy(wszDir, lpszDir); // Get Desktop Folder if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) { // Convert wszDir into a pidl if (NOERROR == lpsfDesktop->ParseDisplayName(hwnd, NULL, wszDir, &chParsed, &pidl, &dwAttributes)) { // Bind pidl to IShellFolder if (NOERROR == lpsfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&lpsf)) { // Create an Enumeration object for lpsf if (NOERROR == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) { // Enumerate the contents of lpsf while (NOERROR == lpe->Next(1, &pidlEntry, NULL)) { // Add found item to the List // Check if it's part of the Filesystem dwAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER; lpsf->GetAttributesOf(1, (LPCITEMIDLIST*)pidlEntry, &dwAttributes); if (dwAttributes & SFGAO_FILESYSTEM) { // Check if item matches specified filter if (DirList_MatchFilter(lpsf, pidlEntry, &dlf)) { lplvid = (LV_ITEMDATA*)CoTaskMemAlloc(sizeof(LV_ITEMDATA)); lplvid->pidl = pidlEntry; lplvid->lpsf = lpsf; lpsf->AddRef(); lvi.lParam = (LPARAM)lplvid; // Setup default Icon - Folder or File lvi.iImage = (dwAttributes & SFGAO_FOLDER) ? lpdl->iDefIconFolder : lpdl->iDefIconFile; ListView_InsertItem(hwnd, &lvi); lvi.iItem++; } } } // IEnumIDList::Next() lpe->Release(); } // IShellFolder::EnumObjects() } // IShellFolder::BindToObject() } // IShellFolder::ParseDisplayName() lpsfDesktop->Release(); } // SHGetDesktopFolder() if (lpdl->pidl) CoTaskMemFree(lpdl->pidl); if (lpdl->lpsf) lpdl->lpsf->Release(); // Set lpdl lpdl->cbidl = IL_GetSize(pidl); lpdl->pidl = pidl; lpdl->lpsf = lpsf; lpdl->bNoFadeHidden = bNoFadeHidden; // Set column width to fit window ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER); // Sort before display is updated DirList_Sort(hwnd, iSortFlags, fSortRev); // Redraw Listview SendMessage(hwnd, WM_SETREDRAW, 1, 0); // Return number of items in the control return (ListView_GetItemCount(hwnd)); }
HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags) { WCHAR szPath[MAX_PATH] = {0}, szBuffer[MAX_PATH]; DWORD dwSize, dwType, count; LONG ret; IShellFolder *pDesktop, *pRecycleBin; PIDLIST_ABSOLUTE pidlRecycleBin; PITEMID_CHILD pidl; HRESULT hr = S_OK; LPENUMIDLIST penumFiles; STRRET StrRet; TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_w(pszRootPath), dwFlags); if (!(dwFlags & SHERB_NOCONFIRMATION)) { hr = SHGetDesktopFolder(&pDesktop); if (FAILED(hr)) return hr; hr = SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidlRecycleBin); if (FAILED(hr)) { pDesktop->Release(); return hr; } hr = pDesktop->BindToObject(pidlRecycleBin, NULL, IID_PPV_ARG(IShellFolder, &pRecycleBin)); CoTaskMemFree(pidlRecycleBin); pDesktop->Release(); if (FAILED(hr)) return hr; hr = pRecycleBin->EnumObjects(hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penumFiles); if (FAILED(hr)) { pRecycleBin->Release(); return hr; } count = 0; if (hr != S_FALSE) { while (penumFiles->Next(1, &pidl, NULL) == S_OK) { count++; pRecycleBin->GetDisplayNameOf(pidl, SHGDN_NORMAL, &StrRet); StrRetToBuf(&StrRet, pidl, szBuffer, _countof(szBuffer)); CoTaskMemFree(pidl); } penumFiles->Release(); } pRecycleBin->Release(); switch (count) { case 0: /* no files, don't need confirmation */ break; case 1: /* we have only one item inside the bin, so show a message box with its name */ if (ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_DELETEITEM_TEXT), MAKEINTRESOURCEW(IDS_EMPTY_BITBUCKET), MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, szBuffer) == IDNO) { return S_OK; } break; default: /* we have more than one item, so show a message box with the count of the items */ StringCbPrintfW(szBuffer, sizeof(szBuffer), L"%u", count); if (ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_DELETEMULTIPLE_TEXT), MAKEINTRESOURCEW(IDS_EMPTY_BITBUCKET), MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, szBuffer) == IDNO) { return S_OK; } break; } } if (dwFlags & SHERB_NOPROGRESSUI) { ret = EmptyRecycleBinW(pszRootPath); } else { /* FIXME * show a progress dialog */ ret = EmptyRecycleBinW(pszRootPath); } if (!ret) return HRESULT_FROM_WIN32(GetLastError()); if (!(dwFlags & SHERB_NOSOUND)) { dwSize = sizeof(szPath); ret = RegGetValueW(HKEY_CURRENT_USER, L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current", NULL, RRF_RT_REG_SZ, &dwType, (PVOID)szPath, &dwSize); if (ret != ERROR_SUCCESS) return S_OK; if (dwType != REG_EXPAND_SZ) /* type dismatch */ return S_OK; szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0'; PlaySoundW(szPath, NULL, SND_FILENAME); } return S_OK; }
//*************************************************************************************** HRESULT CBCGPShellList::EnumObjects (LPSHELLFOLDER pParentFolder, LPITEMIDLIST pidlParent) { ASSERT_VALID (this); ASSERT_VALID (g_pShellManager); LPENUMIDLIST pEnum; HRESULT hRes = pParentFolder->EnumObjects (NULL, m_nTypes, &pEnum); if (SUCCEEDED (hRes)) { LPITEMIDLIST pidlTemp; DWORD dwFetched = 1; LPBCGCBITEMINFO pItem; //enumerate the item's PIDLs while (pEnum->Next(1, &pidlTemp, &dwFetched) == S_OK && dwFetched) { LVITEM lvItem; ZeroMemory(&lvItem, sizeof(lvItem)); //fill in the TV_ITEM structure for this item lvItem.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; //AddRef the parent folder so it's pointer stays valid pParentFolder->AddRef(); //put the private information in the lParam pItem = (LPBCGCBITEMINFO)GlobalAlloc(GPTR, sizeof(BCGCBITEMINFO)); pItem->pidlRel = pidlTemp; pItem->pidlFQ = g_pShellManager->ConcatenateItem (pidlParent, pidlTemp); pItem->pParentFolder = pParentFolder; if (!IsItemMatchedToFilter(pItem)) { ReleaseItem(pItem); dwFetched = 0; continue; } lvItem.lParam = (LPARAM)pItem; lvItem.pszText = _T(""); lvItem.iImage = OnGetItemIcon (GetItemCount (), pItem); //determine if the item is shared DWORD dwAttr = SFGAO_DISPLAYATTRMASK; pParentFolder->GetAttributesOf (1, (LPCITEMIDLIST*)&pidlTemp, &dwAttr); if (dwAttr & SFGAO_SHARE) { lvItem.mask |= LVIF_STATE; lvItem.stateMask |= LVIS_OVERLAYMASK; lvItem.state |= INDEXTOOVERLAYMASK(1); //1 is the index for the shared overlay image } if (dwAttr & SFGAO_GHOSTED) { lvItem.mask |= LVIF_STATE; lvItem.stateMask |= LVIS_CUT; lvItem.state |= LVIS_CUT; } int iItem = InsertItem (&lvItem); if (iItem >= 0) { //------------- // Set columns: //------------- const int nColumns = (GetStyle () & LVS_TYPEMASK) == LVS_REPORT ? m_wndHeader.GetItemCount () : 1; for (int iColumn = 0; iColumn < nColumns; iColumn++) { SetItemText (iItem, iColumn, OnGetItemText (iItem, iColumn, pItem)); } } dwFetched = 0; } pEnum->Release (); } return hRes; }