Примерно так, на основе интерфейса IShellItemImageFactory , который существует с Windows Vista:
CoInitialize(NULL);
{
CComPtr<IKnownFolderManager> mgr;
if (SUCCEEDED(mgr.CoCreateInstance(CLSID_KnownFolderManager)))
{
CComPtr<IKnownFolder> folder;
if (SUCCEEDED(mgr->GetFolder(FOLDERID_ControlPanelFolder, &folder)))
{
CComHeapPtr<ITEMIDLIST> pidl;
// I pass 0 for flags here, but mileage may differ
if (SUCCEEDED(folder->GetIDList(0, &pidl)))
{
CComPtr<IShellItemImageFactory> factory;
if (SUCCEEDED(SHCreateItemFromIDList(pidl, IID_PPV_ARGS(&factory))))
{
// you can vary size and SIIGBF flags
HBITMAP bmp = nullptr;
SIZE size = { 256, 256 };
if (SUCCEEDED(factory->GetImage(size, SIIGBF_ICONONLY, &bmp)))
{
// etc...
DeleteObject(bmp);
}
}
}
}
}
}
CoUninitialize();
И есть даже лучший способ использовать SHCreateItemInKnownFolder функцию :
CoInitialize(NULL);
{
CComPtr<IShellItemImageFactory> factory;
if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_ControlPanelFolder, 0, NULL, IID_PPV_ARGS(&factory))))
{
// you can vary size and SIIGBF flags
HBITMAP bmp = nullptr;
SIZE size = { 256, 256 };
if (SUCCEEDED(factory->GetImage(size, SIIGBF_ICONONLY, &bmp)))
{
// etc...
DeleteObject(bmp);
}
}
}
CoUninitialize();
Обратите внимание, это даст вам значок в виде HBITMAP.