这个例子是在学习Shell程序设计的时候看到的,觉得不错,就记录下来。
#include <windows.h> #include <ShlObj.h> #include <stdio.h> #pragma comment(lib, "Shell32.lib") DWORD ListFileInRecycleBin(); int main() { ListFileInRecycleBin(); system("pause"); return 0; } DWORD ListFileInRecycleBin() { CHAR szPath[MAX_PATH]; IShellFolder *pisf = NULL; IShellFolder *pisfRecBin = NULL; SHGetDesktopFolder(&pisfRecBin); IEnumIDList *peidl = NULL; LPITEMIDLIST pidlBin = NULL; LPITEMIDLIST pidlCurrent = NULL; SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidlBin); pisfRecBin->BindToObject(pidlBin, NULL, IID_IShellFolder, (void**)&pisf); pisf->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &peidl); STRRET strret; ULONG uFetched; HANDLE hOutPut = GetStdHandle(STD_OUTPUT_HANDLE); printf("\nFiles In Recycle Bin:\n"); while (1) { if (S_FALSE == peidl->Next(1, &pidlCurrent, &uFetched)) break; SHGetPathFromIDList(pidlCurrent, szPath); pisf->GetDisplayNameOf(pidlCurrent, SHGDN_NORMAL, &strret); WriteConsoleW(hOutPut, L"\t", 1, NULL, NULL); WriteConsoleW(hOutPut, strret.pOleStr, lstrlenW(strret.pOleStr), NULL, NULL); WriteConsoleW(hOutPut, L"\n", 1, NULL, NULL); } ILFree(pidlBin); ILFree(pidlCurrent); pisf->Release(); pisfRecBin->Release(); peidl->Release(); return 0; }
程序运行结果如下: