windows 修改桌面快捷方式的名字

直接貼代碼~ 

#include <shellapi.h>
#include <shlobj.h>
#pragma  comment(lib, "shell32.lib")
bool _ChangeLinkFile(CString strOrignPath, CString strAferPath)
{
	HRESULT hr = CoInitialize(NULL);
	if (SUCCEEDED(hr))
	{
		IShellLink *pShellLink = NULL;
		IPersistFile *pPf = NULL;
		hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pShellLink);
		if (SUCCEEDED(hr))
		{
			hr = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
			if(!SUCCEEDED(hr))
				return false;

			hr =pPf->Load(strOrignPath, STGM_WRITE);
		
			hr = pPf->Save(strAferPath, true);
			::DeleteFile(strOrignPath);
			pPf->Release();
			pShellLink->Release();
		}
		CoUninitialize();
	}
	return false;

}

主要是通過IShellLinkIPersistFile倆個類的方法實現,可以查看msdn這倆的方法使用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章