//============================================================================= // // IL_Create() // // Creates an ITEMIDLIST by concatenating pidl1 and pidl2 // cb1 and cb2 indicate the sizes of the pidls, where cb1 // can be zero and pidl1 can be NULL // // If cb2 is zero, the size of pidl2 is retrieved using // IL_GetSize(pidl2) // LPITEMIDLIST IL_Create(LPCITEMIDLIST pidl1,UINT cb1, LPCITEMIDLIST pidl2,UINT cb2) { LPITEMIDLIST pidl; if (!pidl2) return NULL; if (!cb2) cb2 = IL_GetSize(pidl2) + 2; // Space for terminating Bytes if (!cb1) cb1 = IL_GetSize(pidl1); // Allocate Memory pidl = CoTaskMemAlloc(cb1 + cb2); // Init new ITEMIDLIST if (pidl1) CopyMemory(pidl,pidl1,cb1); // pidl2 can't be NULL here CopyMemory((LPBYTE)pidl + cb1,pidl2,cb2); return pidl; }
// Creates an ITEMIDLIST by concatenating pidl1 and pidl2 // cb1 and cb2 indicate the sizes of the pidls, where cb1 // can be zero and pidl1 can be NULL // // If cb2 is zero, the size of pidl2 is retrieved using // IL_GetSize(pidl2) LPITEMIDLIST IL_Create(LPCITEMIDLIST pidl1, UINT cb1, LPCITEMIDLIST pidl2, UINT cb2) { LPITEMIDLIST pidl; if (!pidl2) return NULL; if (!cb2) cb2 = IL_GetSize(pidl2) + 2; // Space for terminating Bytes if (!cb1) cb1 = IL_GetSize(pidl1); pidl = (LPITEMIDLIST)CoTaskMemAlloc(cb1 + cb2); if (pidl1) CopyMemory(pidl, pidl1, cb1); CopyMemory((LPBYTE)pidl + cb1, pidl2, cb2); return pidl; }
//============================================================================= // // DirList_Fill() // // Snapshots a directory and displays the items in the listview control // int DirList_Fill(HWND hwnd,LPCWSTR lpszDir,DWORD grfFlags,LPCWSTR 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; LPDLDATA lpdl = (LPVOID)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->lpVtbl->ParseDisplayName( lpsfDesktop, hwnd, NULL, wszDir, &chParsed, &pidl, &dwAttributes)) { // Bind pidl to IShellFolder if (NOERROR == lpsfDesktop->lpVtbl->BindToObject( lpsfDesktop, pidl, NULL, &IID_IShellFolder, &lpsf)) { // Create an Enumeration object for lpsf if (NOERROR == lpsf->lpVtbl->EnumObjects( lpsf, hwnd, grfFlags, &lpe)) { // Enumerate the contents of lpsf while (NOERROR == lpe->lpVtbl->Next( lpe, 1, &pidlEntry, NULL)) { // Add found item to the List // Check if it's part of the Filesystem dwAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER; lpsf->lpVtbl->GetAttributesOf( lpsf, 1, &pidlEntry, &dwAttributes); if (dwAttributes & SFGAO_FILESYSTEM) { // Check if item matches specified filter if (DirList_MatchFilter(lpsf,pidlEntry,&dlf)) { lplvid = CoTaskMemAlloc(sizeof(LV_ITEMDATA)); lplvid->pidl = pidlEntry; lplvid->lpsf = lpsf; lpsf->lpVtbl->AddRef(lpsf); 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->lpVtbl->Release(lpe); } // IShellFolder::EnumObjects() } // IShellFolder::BindToObject() } // IShellFolder::ParseDisplayName() lpsfDesktop->lpVtbl->Release(lpsfDesktop); } // SHGetDesktopFolder() if (lpdl->pidl) CoTaskMemFree(lpdl->pidl); if (lpdl->lpsf && lpdl->lpsf->lpVtbl) lpdl->lpsf->lpVtbl->Release(lpdl->lpsf); // 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)); }