//更改桌面图标
wchar_t path[1024];
SHGetSpecialFolderPath(0, path, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
wstring DesktopPath(path);
DesktopPath.append(L"\\xxxx.lnk");
//MessageBox(0, DesktopPath.c_str(),NULL,NULL);
wstring wsIconPath = ui::PathUtil::GetCurrentModuleDir();
wsIconPath += L".ico";
if (!PathFileExists(DesktopPath.c_str()))
{
DesktopPath.clear();
wmemset(path,0,1024);
SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, 0);
DesktopPath = path;
DesktopPath.append(L"\\xxx.lnk");
//MessageBox(0, DesktopPath.c_str(), NULL, NULL);
}
if (PathFileExists(wsIconPath.c_str()))
{
ChangeLinkIcon(DesktopPath, wsIconPath);
}
bool ChangeLinkIcon(const wstring &strLnkName, const wstring &strIconPath)
{
if (strLnkName.empty() || strIconPath.empty())
{
return false;
}
HRESULT hres;
IShellLink *psl = NULL;
IPersistFile *pPf = NULL;
int id;
LPITEMIDLIST pidl;
bool bRet = false;
do
{
hres = CoInitialize(NULL);
if (FAILED(hres))
{
break;
}
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (FAILED(hres))
{
break;
}
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
if (FAILED(hres))
{
break;
}
hres = pPf->Load(strLnkName.c_str(), STGM_READWRITE);
if (FAILED(hres))
{
break;
}
hres = psl->SetIconLocation(strIconPath.c_str(), 0);
if (FAILED(hres))
{
break;
}
pPf->Save(strLnkName.c_str(), TRUE);
if (FAILED(hres))
{
break;
}
bRet = true;
} while (0);
if (pPf != NULL)
{
pPf->Release();
}
if (psl != NULL)
{
psl->Release();
}
CoUninitialize();
return bRet;
}