|
- #include <windows.h>
- #include <shlobj.h> // For SHGetDesktopFolder and related functions
- #include <tchar.h>
- #include <objbase.h> // For CoInitializeEx
- #include <strsafe.h>
- #pragma comment(lib, "shell32.lib")
- // Function to display the name of a file or folder
- void DisplayItemName(IShellFolder* pDesktopFolder, PCUIDLIST_RELATIVE pidl)
- {
- LPWSTR pszName = nullptr;
- if (SUCCEEDED(pDesktopFolder->GetDisplayNameOf(pidl, SHGDN_NORMAL, &pszName)))
- {
- OutputDebugStringW(pszName);
- CoTaskMemFree(pszName);
- }
- }
- int main()
- {
- HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
- if (SUCCEEDED(hr))
- {
- IShellFolder* pDesktopFolder = NULL;
- hr = SHGetDesktopFolder(&pDesktopFolder);
- if (SUCCEEDED(hr))
- {
- UINT cFetched = 0;
- PCUIDLIST_RELATIVE pidl;
- while (S_OK == (hr = pDesktopFolder->EnumObjects(NULL, 0, &pidl, 1, &cFetched)) && cFetched > 0)
- {
- DisplayItemName(pDesktopFolder, pidl);
- pDesktopFolder->ExtractIcon(NULL, pidl, 0, NULL, NULL, 0, NULL, NULL);
- ILFree(pidl);
- cFetched = 0;
- }
- pDesktopFolder->Release();
- }
- CoUninitialize();
- }
- return 0;
- }
复制代码 |
|