枚举桌面图标
本帖最后由 兵三进一 于 2024-10-5 08:32 编辑水平有限,拒绝献丑:)
感谢大佬贡献 创世魂 发表于 2023-7-16 10:49
感谢大佬贡献
老大真会开玩笑,整得俺受宠若惊了:) 感谢大佬贡献 我看看怎么个事 1111111
111111111111111111 #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;
}
页:
[1]