创建快捷方式到桌面、任务栏、开始菜单、快速启动栏、程序组中

前端之家收集整理的这篇文章主要介绍了创建快捷方式到桌面、任务栏、开始菜单、快速启动栏、程序组中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//得到快速启动栏的路径    
BOOL GetIEQuickLaunchPath(WCHAR *pszIEQueickLaunchPath)
{
	LPITEMIDLIST  ppidl;

	if (SHGetSpecialFolderLocation(NULL,CSIDL_APPDATA,&ppidl) == S_OK)
	{
		BOOL flag = SHGetPathFromIDList(ppidl,pszIEQueickLaunchPath);
		wcscat(pszIEQueickLaunchPath,L"\\Microsoft\\Internet Explorer\\Quick Launch");
		CoTaskMemFree(ppidl);
		return flag;
	}
	return FALSE;
}

//得到 开始->程序组 的路径    
BOOL GetProgramsPath(WCHAR *pszProgramsPath)
{
	LPITEMIDLIST  ppidl;

	if (SHGetSpecialFolderLocation(NULL,CSIDL_STARTMENU,pszProgramsPath);
		CoTaskMemFree(ppidl);
		return flag;
	}
	return FALSE;
}

//得到当前桌面路径    
BOOL GetDesktopPath(WCHAR *pszDesktopPath)
{
	LPITEMIDLIST  ppidl = NULL;

	if (SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOP,pszDesktopPath);
		CoTaskMemFree(ppidl);
		return flag;
	}
	return FALSE;
}

bool CreateShortcut(const WCHAR* pszSrcPath)
{
	CoInitialize(NULL);

	bool bRet = false;

	WCHAR chQuick[MAX_PATH] = { 0 };
	WCHAR chPrograms[MAX_PATH] = { 0 };
	WCHAR chDesktop[MAX_PATH] = { 0 };
	GetDesktopPath(chDesktop);
	GetIEQuickLaunchPath(chQuick);
	GetProgramsPath(chPrograms);

	std::wstring str;
	str = chQuick;

	WCHAR szFileTitle[MAX_PATH] = { 0 };
	::GetFileTitle(pszSrcPath,szFileTitle,MAX_PATH);

	str += L"//";
	str += std::wstring(szFileTitle);
	str += L".lnk";

	IShellLink* psl;
	HRESULT hr = CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(LPVOID*)&psl);
	if (SUCCEEDED(hr)) {
		IPersistFile* ppf;
		psl->SetPath(pszSrcPath);
		psl->SetDescription(L"测试描述");
		psl->SetShowCmd(SW_SHOW);
		if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile,(LPVOID *)&ppf))) {
			if (SUCCEEDED(ppf->Save(str.c_str(),TRUE)))
				bRet = true;
			ppf->Release();
		}
		psl->Release();
	}

	CoUninitialize();


	::ShellExecute(NULL,TEXT("StartPin"),str.c_str(),SW_SHOW);//锁定到开始菜单
	::ShellExecute(NULL,L"TaskbarPin",SW_SHOW);//锁定到任务栏
	return bRet;
}
原文链接:https://www.f2er.com/bash/389456.html

猜你在找的Bash相关文章